### Question:
EventLogging implements TWidget { public boolean canWrite() { if (writingRate == 0) return true; int mode = Math.abs(random.nextInt()) % 100; return (mode <= writingRate); }  void setName(String name); @Required void setFormat(String format); @Required void setLevel(String level); void log(TEvent event); boolean canWrite();  }### Answer:
@Test public void testRate() { EventLogging logging = new EventLogging(); logging.writingRate = 50; int t = 0; for (int i = 0; i < 100 * 10000; i++) { if (logging.canWrite()) { t += 1; } } t = (t / 10000 ); Assert.assertTrue(t >= 40 && t <= 60); logging.writingRate = 20; t = 0; for (int i = 0; i < 100 * 10000; i++) { if (logging.canWrite()) { t += 1; } } t = (t / 10000 ); Assert.assertTrue(t >= 10 && t <= 30); logging.writingRate = 80; t = 0; for (int i = 0; i < 100 * 10000; i++) { if (logging.canWrite()) { t += 1; } } t = (t / 10000 ); Assert.assertTrue(t >= 70 && t <= 90); }