diff --git a/classes/swen90006/machine/BoundaryTests.class b/classes/swen90006/machine/BoundaryTests.class index 8cc735a2d9ab7d28119bd13db1a8e979a6cfb1ed..2ba0555264cb67e19f67bce50ede5c9c692d5d05 100644 Binary files a/classes/swen90006/machine/BoundaryTests.class and b/classes/swen90006/machine/BoundaryTests.class differ diff --git a/classes/swen90006/machine/PartitioningTests.class b/classes/swen90006/machine/PartitioningTests.class index 185cbdc5c0d85810511dafeb9e5684f17ad14be8..b084b43b945ece63ee63632a5d84c0904474e340 100644 Binary files a/classes/swen90006/machine/PartitioningTests.class and b/classes/swen90006/machine/PartitioningTests.class differ diff --git a/classes/swen90006/machine/SimpleDriver.class b/classes/swen90006/machine/SimpleDriver.class index 5ec33d8d060b554c3f39b6814357650e46541be2..48a6bba6927d7bdb6eb1ade861cf2706744f5b38 100644 Binary files a/classes/swen90006/machine/SimpleDriver.class and b/classes/swen90006/machine/SimpleDriver.class differ diff --git a/src/swen90006/machine/SimpleDriver.java b/src/swen90006/machine/SimpleDriver.java index dbeb3e5379f73c3f363acf25723e6591af1740b5..bf288a4d2d3262d62316a7fa8adeb2a9f9a1dd6e 100644 --- a/src/swen90006/machine/SimpleDriver.java +++ b/src/swen90006/machine/SimpleDriver.java @@ -45,6 +45,7 @@ public class SimpleDriver { if (m != null){ System.err.println("Number of instructions executed before exception: " + m.getCount()); } + System.exit(1); } } } diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 36649bb0b96f82cca8dbec83f3c35ac469dca846..d3a53c0aad9952225c70e649cca9d939e1255547 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -12,96 +12,158 @@ import static org.junit.Assert.*; public class BoundaryTests { + + + private List<String> readInstructions(String file) + { + Charset charset = Charset.forName("UTF-8"); + List<String> lines = null; + try { + lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + } + catch (Exception e){ + System.err.println("Invalid input file! (stacktrace follows)"); + e.printStackTrace(System.err); + System.exit(1); + } + return lines; + } @Test public void boundaryTest1() throws Exception { - SimpleDriver.main(new String[]{"examples/BV1.s"}); + final List<String> lines = readInstructions("examples/BV1.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void boundaryTest2() throws Exception { - SimpleDriver.main(new String[]{"examples/BV2.s"}); + final List<String> lines = readInstructions("examples/BV2.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 2); } @Test public void boundaryTest3() throws Exception { - SimpleDriver.main(new String[]{"examples/BV3.s"}); + final List<String> lines = readInstructions("examples/BV3.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void boundaryTest4() throws Exception { - SimpleDriver.main(new String[]{"examples/BV4.s"}); + final List<String> lines = readInstructions("examples/BV4.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void boundaryTest5() throws Exception { - SimpleDriver.main(new String[]{"examples/BV5.s"}); + final List<String> lines = readInstructions("examples/BV5.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest6() throws Exception { - SimpleDriver.main(new String[]{"examples/BV6.s"}); + final List<String> lines = readInstructions("examples/BV6.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest7() throws Exception { - SimpleDriver.main(new String[]{"examples/BV7.s"}); + final List<String> lines = readInstructions("examples/BV7.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void boundaryTest8() throws Exception { - SimpleDriver.main(new String[]{"examples/BV8.s"}); + final List<String> lines = readInstructions("examples/BV8.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void boundaryTest9() throws Exception { - SimpleDriver.main(new String[]{"examples/BV9.s"}); + final List<String> lines = readInstructions("examples/BV9.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); } @Test public void boundaryTest10() throws Exception { - SimpleDriver.main(new String[]{"examples/BV10.s"}); + final List<String> lines = readInstructions("examples/BV10.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 6); } @Test public void boundaryTest11() throws Exception { - SimpleDriver.main(new String[]{"examples/BV11.s"}); + final List<String> lines = readInstructions("examples/BV11.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 7); } @Test public void boundaryTest12() throws Exception { - SimpleDriver.main(new String[]{"examples/BV12.s"}); + final List<String> lines = readInstructions("examples/BV12.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); } @Test public void boundaryTest13() throws Exception { - SimpleDriver.main(new String[]{"examples/BV13.s"}); + final List<String> lines = readInstructions("examples/BV13.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest14() throws Exception { - SimpleDriver.main(new String[]{"examples/BV14.s"}); + final List<String> lines = readInstructions("examples/BV14.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest15() throws Exception { - SimpleDriver.main(new String[]{"examples/BV15.s"}); + final List<String> lines = readInstructions("examples/BV15.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest16() throws Exception { - SimpleDriver.main(new String[]{"examples/BV16.s"}); + final List<String> lines = readInstructions("examples/BV16.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest17() throws Exception { - SimpleDriver.main(new String[]{"examples/BV17.s"}); + final List<String> lines = readInstructions("examples/BV17.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest18() throws Exception { - SimpleDriver.main(new String[]{"examples/BV18.s"}); + final List<String> lines = readInstructions("examples/BV18.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest19() throws Exception { - SimpleDriver.main(new String[]{"examples/BV19.s"}); + final List<String> lines = readInstructions("examples/BV19.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } @Test public void boundaryTest20() throws Exception { - SimpleDriver.main(new String[]{"examples/BV20.s"}); + final List<String> lines = readInstructions("examples/BV20.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 1); } @Test public void boundaryTest21() throws Exception { - SimpleDriver.main(new String[]{"examples/BV21.s"}); + final List<String> lines = readInstructions("examples/BV21.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 6); } @Test public void boundaryTest22() throws Exception { - SimpleDriver.main(new String[]{"examples/BV22.s"}); + final List<String> lines = readInstructions("examples/BV22.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 6); } @Test public void boundaryTest23() throws Exception { - SimpleDriver.main(new String[]{"examples/BV23.s"}); + final List<String> lines = readInstructions("examples/BV23.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 6); } } diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 33c35feeb485d89663cd58a60f33103fc4bd48e5..d7e2d2f89e5a2a9d6cd5807ec1d4658d12d60292 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -12,79 +12,120 @@ import static org.junit.Assert.*; public class PartitioningTests { + private List<String> readInstructions(String file){ + Charset charset = Charset.forName("UTF-8"); + List<String> lines = null; + try { + lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + } + catch (Exception e){ + System.err.println("Invalid input file! (stacktrace follows)"); + e.printStackTrace(System.err); + System.exit(1); + } + return lines; + } @Test public void partitionTest1() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC1.s"}); + final List<String> lines = readInstructions("examples/EC1.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 9); } @Test public void partitionTest2() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC2.s"}); + final List<String> lines = readInstructions("examples/EC2.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void partitionTest3() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC3.s"}); - + final List<String> lines = readInstructions("examples/EC3.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 3); } @Test public void partitionTest4() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC4.s"}); + final List<String> lines = readInstructions("examples/EC4.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 9); } @Test public void partitionTest5() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC5.s"}); + final List<String> lines = readInstructions("examples/EC5.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 2); } @Test public void partitionTest6() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC6.s"}); + final List<String> lines = readInstructions("examples/EC6.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 2); } @Test public void partitionTest7() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC7.s"}); + final List<String> lines = readInstructions("examples/EC7.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 7); } @Test public void partitionTest8() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC8.s"}); + final List<String> lines = readInstructions("examples/EC8.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); } @Test public void partitionTest9() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC9.s"}); + final List<String> lines = readInstructions("examples/EC9.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 1); } @Test public void partitionTest10() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC10.s"}); + final List<String> lines = readInstructions("examples/EC10.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 1); } @Test public void partitionTest11() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC11.s"}); - + final List<String> lines = readInstructions("examples/EC11.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); } @Test public void partitionTest12() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC12.s"}); + final List<String> lines = readInstructions("examples/EC12.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 5); } @Test public void partitionTest131() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC13-1.s"}); + final List<String> lines = readInstructions("examples/EC13-1.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 1); } @Test public void partitionTest132() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC13-2.s"}); + final List<String> lines = readInstructions("examples/EC13-2.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 1); } @Test public void partitionTest14() throws Exception{ - SimpleDriver.main(new String[]{"examples/EC14.s"}); + final List<String> lines = readInstructions("examples/EC14.s"); + Machine m = new Machine(); + assertEquals(m.execute(lines), 4); } }