@Test
  public void testConstructorMilli() {
    StopWatch s = new StopWatch(0);
    assertEquals(s.toString(), "0:00:000");

    s = new StopWatch(1);
    assertEquals(s.toString(), "0:00:001");

    s = new StopWatch(999);
    assertEquals(s.toString(), "0:00:999");
  }
  @Test
  public void testConstructorString() {
    StopWatch s = new StopWatch("0:0:0");
    assertEquals(s.toString(), "0:00:000");

    s = new StopWatch("1:1:1");
    assertEquals(s.toString(), "1:01:001");

    s = new StopWatch("9999:59:999");
    assertEquals(s.toString(), "9999:59:999");
  }
  @Test
  public void testLoadSave() {
    StopWatch s1 = new StopWatch(5, 59, 300);
    assertEquals(s1.toString(), "5:59:300");

    s1.save("file1");
    s1 = new StopWatch();
    assertEquals(s1.toString(), "0:00:000");

    s1.load("file1");
    assertEquals(s1.toString(), "5:59:300");
  }
  @Test
  public void testConstructor() {
    StopWatch s = new StopWatch(5, 10, 300);
    assertEquals(s.toString(), "5:10:300");

    s = new StopWatch("20:10:8");
    assertEquals(s.toString(), "20:10:008");

    s = new StopWatch("20:8");
    assertEquals(s.toString(), "0:20:008");

    s = new StopWatch("8");
    assertEquals(s.toString(), "0:00:008");
  }
  @Test
  public void testConstructorSec() {
    StopWatch s = new StopWatch(0, 0);
    assertEquals(s.toString(), "0:00:000");

    s = new StopWatch(1, 0);
    assertEquals(s.toString(), "0:01:000");

    s = new StopWatch(1, 1);
    assertEquals(s.toString(), "0:01:001");

    s = new StopWatch(59, 999);
    assertEquals(s.toString(), "0:59:999");
  }
  @Test
  public void testAddMethod() {
    StopWatch s1 = new StopWatch(5, 59, 300);
    s1.add(2000);
    assertEquals(s1.toString(), "6:01:300");

    s1 = new StopWatch(5, 59, 300);
    StopWatch s2 = new StopWatch(2, 2, 300);
    s1.add(s2);
    System.out.println(s1);
    assertEquals(s1.toString(), "8:01:600");

    for (int i = 0; i < 15000; i++) s1.inc();
    System.out.println(s1);
    assertEquals(s1.toString(), "8:16:600");
  }
  @Test
  public void testToString() {
    StopWatch s1 = new StopWatch();
    assertEquals(s1.toString(), "0:00:000");

    StopWatch s2 = new StopWatch(1234, 53, 867);
    assertEquals(s2.toString(), "1234:53:867");

    StopWatch s3 = new StopWatch(0, 0, 0);
    assertEquals(s3.toString(), "0:00:000");

    StopWatch s4 = new StopWatch(1, 1, 1);
    assertEquals(s4.toString(), "1:01:001");

    StopWatch s5 = new StopWatch(22, 30, 900);
    assertEquals(s5.toString(), "22:30:900");
  }
Ejemplo n.º 8
0
  /** Tests the functionality of toString() */
  public void testToString() {
    StopWatch watch = new StopWatch();

    try {
      Thread.sleep(10);
    } catch (InterruptedException e) {
    }
    watch.stop();
    assertEquals(watch.getTimeDiffString(), watch.toString());
  }
 @Test
 public void testDefaultConstructor() {
   StopWatch s = new StopWatch();
   assertEquals(s.toString(), "0:00:000");
 }