/** * On Mac/Linux: * javac -cp .:junit-cs211.jar *.java # compile everything * java -cp .:junit-cs211.jar E3tester # run tests * * On windows replace colons with semicolons: (: with ;) * javac -cp .;junit-cs211.jar *.java # compile everything * java -cp .;junit-cs211.jar E3tester # run tests */ import org.junit.*; import static org.junit.Assert.*; import java.util.*; public class E3tester { public static void main(String args[]){ org.junit.runner.JUnitCore.main("E3tester"); } @Test public void stopwatch_01() { Stopwatch sw = new Stopwatch(); try { Thread.sleep(500); } catch(Exception e) {} double dt = sw.check(); assertEquals( 0.5, dt, 0.1 ); } @Test public void stopwatch_02() { Stopwatch sw = new Stopwatch(); try { Thread.sleep(1000); } catch(Exception e) {} double dt = sw.check(); assertEquals( 1.0, dt, 0.1 ); } @Test public void stopwatch_03() { Stopwatch sw = new Stopwatch(); try { Thread.sleep(1500); } catch(Exception e) {} double dt = sw.check(); assertEquals( 1.5, dt, 0.1 ); } @Test public void stopwatch_04() { Stopwatch sw = new Stopwatch(); try { Thread.sleep(2000); } catch(Exception e) {} double dt = sw.check(); assertEquals( 2.0, dt, 0.1 ); } @Test public void stopwatch_05() { Stopwatch sw = new Stopwatch(); try { Thread.sleep(1000); } catch(Exception e) {} sw.reset(); try { Thread.sleep(1000); } catch(Exception e) {} double dt = sw.check(); assertEquals( 1.0, dt, 0.1 ); } @Test public void accumulator_01() { Accumulator acc = new Accumulator(); assertEquals( 0.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_02() { Accumulator acc = new Accumulator(); acc.add(1.0); assertEquals( 1.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_03() { Accumulator acc = new Accumulator(); acc.add(1.0); acc.add(1.0); assertEquals( 2.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_04() { Accumulator acc = new Accumulator(); acc.add(1.0); acc.add(1.0); acc.add(2.0); assertEquals( 4.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_05() { Accumulator acc = new Accumulator(); acc.add(1.0); acc.add(1.0); acc.add(2.0); acc.add(3.5); assertEquals( 7.5, acc.getTotal(), 0.0001 ); } @Test public void accumulator_06() { Accumulator acc = new Accumulator(); acc.add(1.0); acc.add(1.0); acc.add(2.0); acc.add(3.5); acc.add(-1.0); assertEquals( 6.5, acc.getTotal(), 0.0001 ); } @Test public void accumulator_07() { Accumulator acc = new Accumulator(); acc.add(1.0); acc.add(1.0); acc.reset(); acc.add(1.0); acc.add(1.0); assertEquals( 2.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_readNumbers_00() { Accumulator acc = new Accumulator(); acc.readNumbers(""); assertEquals( 0.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_readNumbers_01() { Accumulator acc = new Accumulator(); acc.readNumbers("1.0"); assertEquals( 1.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_readNumbers_02() { Accumulator acc = new Accumulator(); acc.readNumbers("1.0 2.0"); assertEquals( 3.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_readNumbers_03() { Accumulator acc = new Accumulator(); acc.readNumbers("1.0 2.0 xyz"); assertEquals( 3.0, acc.getTotal(), 0.0001 ); } @Test public void accumulator_readNumbers_04() { Accumulator acc = new Accumulator(); acc.readNumbers("1.0 2.0 xyz -1.2"); assertEquals( 1.8, acc.getTotal(), 0.0001 ); } }