diff --git a/mutants/mutant-1/swen90006/machine/Machine.java b/mutants/mutant-1/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..d1c089f1e53ab80acfdd9ce0418808ba319fe785 100644 --- a/mutants/mutant-1/swen90006/machine/Machine.java +++ b/mutants/mutant-1/swen90006/machine/Machine.java @@ -266,7 +266,7 @@ public class Machine throw new InvalidInstructionException(); } int offs = parseOffset(toks[1]); - pc = pc + offs; + pc = offs;//pc = pc + offs; count++; continue; /* avoid default increment of pc below */ } else if (toks[0].equals(INSTRUCTION_JZ)){ @@ -283,6 +283,7 @@ public class Machine count++; continue; /* avoid default increment the pc below */ } else { + System.err.println("Unrecognised instruction: " + inst); throw new InvalidInstructionException(); } diff --git a/mutants/mutant-2/swen90006/machine/Machine.java b/mutants/mutant-2/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..6992b338f42e000f1523744c8ca2cb6fdbfc23c2 100644 --- a/mutants/mutant-2/swen90006/machine/Machine.java +++ b/mutants/mutant-2/swen90006/machine/Machine.java @@ -275,7 +275,7 @@ public class Machine } int ra = parseReg(toks[1]); int offs = parseOffset(toks[2]); - if (regs[ra] == 0){ + if (regs[ra] <= 0){ pc = pc + offs; }else{ pc = pc + 1; diff --git a/mutants/mutant-3/swen90006/machine/Machine.java b/mutants/mutant-3/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..9ef4302a2ac614c0e9e8d8557ff0db71d5f53d9b 100644 --- a/mutants/mutant-3/swen90006/machine/Machine.java +++ b/mutants/mutant-3/swen90006/machine/Machine.java @@ -188,7 +188,7 @@ public class Machine /* check for blank lines */ if (inst.equals("")){ - pc = pc + 1; + pc += pc + 1; count++; continue; } diff --git a/mutants/mutant-4/swen90006/machine/Machine.java b/mutants/mutant-4/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..1dd1bf84c7214959f356eaab24c01425b1c097e3 100644 --- a/mutants/mutant-4/swen90006/machine/Machine.java +++ b/mutants/mutant-4/swen90006/machine/Machine.java @@ -128,7 +128,7 @@ public class Machine { int num = 0; try { - num = Integer.parseInt(s); + num = Math.abs(Integer.parseInt(s));; } catch (Exception e){ throw new InvalidInstructionException(); } diff --git a/mutants/mutant-5/swen90006/machine/Machine.java b/mutants/mutant-5/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..2562cb2a55dae777877fa919eafae9ee15054844 100644 --- a/mutants/mutant-5/swen90006/machine/Machine.java +++ b/mutants/mutant-5/swen90006/machine/Machine.java @@ -170,7 +170,7 @@ public class Machine int pc = 0; final int progLength = instructions.size(); while(true){ - if (pc < 0 || pc >= progLength){ + if (pc < 0 || pc > progLength){ /* will cause NoReturnValueException to be thrown * but that is not a bug and and indeed is what the * VM is supposed to do if the pc becomes negative, diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 61ce1ca647f325fbf452047408c1e22d9befcb99..9ea7aa2c9d50be7cbf010b12e4909bc8d5c3d604 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -24,53 +24,6 @@ public class BoundaryTests { } - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() - { - //the assertEquals method used to check whether two values are - //equal, using the equals method - final int expected = 2; - final int actual = 1 + 1; - assertEquals(expected, actual); - } - - @Test public void anotherTest() - { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); - - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); - } - - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() - { - final List<String> lines = readInstructions("examples/array.s"); - Machine m = new Machine(); - assertEquals(m.execute(lines), 45); - } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable - { - throw new java.io.IOException(); - } - - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); - } - //Read in a file containing a program and convert into a list of //string instructions private List<String> readInstructions(String file) @@ -87,4 +40,206 @@ public class BoundaryTests } return lines; } + + //------My test cases-------------- + @Test (expected = Exception.class) + public void B1() { + final List<String> lines = new ArrayList(); + lines.add(""); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B2() { + final List<String> lines = new ArrayList(); + lines.add("aaaa"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B3() { + final List<String> lines = new ArrayList(); + lines.add("MOV R0 0"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B4() { + final List<String> lines = new ArrayList(); + lines.add("MOV R-1 0"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B5() { + final List<String> lines = new ArrayList(); + lines.add("ADD R31 R1 R2"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B6() { + final List<String> lines = new ArrayList(); + lines.add("ADD R32 R1 R2"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B7() { + final List<String> lines = new ArrayList(); + lines.add("LDR R1 R0 -65536"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B8() { + final List<String> lines = new ArrayList(); + lines.add("LDR R1 R0 -65537"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B9() { + final List<String> lines = new ArrayList(); + lines.add("STR R0 65535 R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B10() { + final List<String> lines = new ArrayList(); + lines.add("STR R0 65536 R1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test + public void B11() { + final List<String> lines = new ArrayList(); + lines.add("RET R1"); + Machine m = new Machine(); + assertEquals(0, m.execute(lines)); + } + + @Test (expected = NoReturnValueException.class) + public void B12() { + final List<String> lines = new ArrayList(); + lines.add("JZ R1 -1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B13() { + final List<String> lines = new ArrayList(); + lines.add("MUL R2 R1 R0"); + lines.add("XXX XX XX XX"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test + public void B14() { + final List<String> lines = new ArrayList(); + lines.add("div r0 R1 R2"); + lines.add("RET R0"); + Machine m = new Machine(); + assertEquals(0, m.execute(lines)); + + } + + @Test (expected = InvalidInstructionException.class) + public void B15() { + final List<String> lines = new ArrayList(); + lines.add("DIV R0 R1 R2"); + lines.add("RET R-1"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B16() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 0"); + lines.add("JZ R31 4"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B17() { + final List<String> lines = new ArrayList(); + Machine m = new Machine(); + lines.add("MOV R1 0"); + lines.add("JZ R32 4"); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B18() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 0"); + lines.add("JMP -65536"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B19() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 0"); + lines.add("JMP -65537"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B20() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 -3"); + lines.add("JZ R1 4"); + lines.add("MOV R1 65535"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = InvalidInstructionException.class) + public void B21() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 -3"); + lines.add("JZ R1 4"); + lines.add("MOV R1 65536"); + Machine m = new Machine(); + m.execute(lines); + } + + @Test (expected = NoReturnValueException.class) + public void B22() { + final List<String> lines = new ArrayList(); + Machine m = new Machine(); + lines.add(""); + lines.add("SUB R2 R1 R0"); + lines.add("JMP 3"); + lines.add("RET R2"); + m.execute(lines); + } + + @Test + public void B23() { + final List<String> lines = new ArrayList(); + Machine m = new Machine(); + lines.add("MOV R1 -1"); + lines.add("RET R1"); + assertEquals(-1, m.execute(lines)); + } + } diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 5494b44f4615351a610fc7b0b649d30b4b2d0a40..d18f4a7d7155a82b105415a21e975c07a6e2eced 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -24,53 +24,126 @@ public class PartitioningTests { } - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() - { - //the assertEquals method used to check whether two values are - //equal, using the equals method - final int expected = 2; - final int actual = 1 + 1; - assertEquals(expected, actual); + @Test (expected = Exception.class) + public void EC1() { + final List<String> lines = new ArrayList(); + Machine m = new Machine(); + m.execute(lines); } - - @Test public void anotherTest() - { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); - - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); + + @Test (expected = InvalidInstructionException.class) + public void EC2() { + final List<String> lines = new ArrayList(); + lines.add("aaaa"); + Machine m = new Machine(); + m.execute(lines); } - - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() - { - final List<String> lines = readInstructions("examples/array.s"); - Machine m = new Machine(); - assertEquals(m.execute(lines), 45); + + @Test (expected = InvalidInstructionException.class) + public void EC3() { + final List<String> lines = new ArrayList(); + lines.add("MOV R-1 0"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC4() { + final List<String> lines = new ArrayList(); + lines.add("ADD R32 R1 R2"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC5() { + final List<String> lines = new ArrayList(); + lines.add("LDR R1 R0 -65537"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC6() { + final List<String> lines = new ArrayList(); + lines.add("STR R0 65536 R1"); + Machine m = new Machine(); + m.execute(lines); } - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable - { - throw new java.io.IOException(); + @Test + public void EC7() { + final List<String> lines = new ArrayList(); + lines.add("RET R1"); + Machine m = new Machine(); + assertEquals(0, m.execute(lines)); } - - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); + + @Test (expected = NoReturnValueException.class) + public void EC8() { + final List<String> lines = new ArrayList(); + lines.add("JZ R1 -1"); + Machine m = new Machine(); + m.execute(lines); } - + @Test (expected = InvalidInstructionException.class) + public void EC9() { + final List<String> lines = new ArrayList(); + lines.add("MUL R2 R1 R0"); + lines.add("xxx xx xx xx"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC10() { + final List<String> lines = new ArrayList(); + lines.add("DIV R2 R1 R0"); + lines.add("RET R-1"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC11() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 0"); + lines.add("JZ R32 4"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC12() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 0"); + lines.add("JMP -65537"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = InvalidInstructionException.class) + public void EC13() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 -3"); + lines.add("JZ R1 4"); + lines.add("MOV R1 65536"); + Machine m = new Machine(); + m.execute(lines); + } + @Test (expected = NoReturnValueException.class) + public void EC14() { + final List<String> lines = new ArrayList(); + lines.add(""); + lines.add("SUB R2 R1 R0"); + lines.add("JMP 3"); + lines.add("RET R2"); + Machine m = new Machine(); + m.execute(lines); + } + @Test + public void EC15() { + final List<String> lines = new ArrayList(); + lines.add("MOV R1 -1"); + lines.add(""); + lines.add("RET R1"); + Machine m = new Machine(); + assertEquals(-1, m.execute(lines)); + } + //Read in a file containing a program and convert into a list of //string instructions private List<String> readInstructions(String file)