|
|
@@ -18,18 +18,20 @@ import net.ranides.assira.text.StringUtils;
|
|
|
*/
|
|
|
public class TimeMetricTest {
|
|
|
|
|
|
+ public static final double DELTA = 25.0;
|
|
|
+
|
|
|
@Test
|
|
|
public void testStop() throws InterruptedException {
|
|
|
TimeMetric tm = new TimeMetric(TimeUnit.MILLISECONDS);
|
|
|
tm.start();
|
|
|
|
|
|
- Thread.sleep(50);
|
|
|
- assertTimerText(50, "ms", tm);
|
|
|
- assertEquals(50.0, tm.stop(), 25.0);
|
|
|
-
|
|
|
- Thread.sleep(50);
|
|
|
+ Thread.sleep(100);
|
|
|
assertTimerText(100, "ms", tm);
|
|
|
- assertEquals(100.0, tm.stop(), 25.0);
|
|
|
+ assertEquals(100.0, tm.stop(), DELTA);
|
|
|
+
|
|
|
+ Thread.sleep(100);
|
|
|
+ assertTimerText(200, "ms", tm);
|
|
|
+ assertEquals(200.0, tm.stop(), DELTA);
|
|
|
|
|
|
assertThrows(NoSuchElementException.class, ()->{
|
|
|
System.out.printf("%d%n", tm.stop());
|
|
|
@@ -40,7 +42,7 @@ public class TimeMetricTest {
|
|
|
String text = tm.toString();
|
|
|
assertTrue("Invalid unit: " + text, text.endsWith("ms"));
|
|
|
int number = Integer.parseInt(StringUtils.before(text, "ms"));
|
|
|
- assertEquals(value, number, 25.0);
|
|
|
+ assertEquals(value, number, DELTA);
|
|
|
}
|
|
|
|
|
|
}
|