diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 86feef88b4f58d37ded53f7ede91e70eb947e5f2..2fc557cee83feae812ce774b9bc8153fc799e8c0 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -42,7 +42,9 @@ public class BoundaryTests //the assertEquals method used to check whether two values are //equal, using the equals method List<String> list = new ArrayList<String>(); - list.add("MOV R31 31"); + list.add("MOV R1 1"); + list.add("MOV R2 2"); + list.add("ADD R31 R1 R2"); list.add("RET R31"); Machine machine = new Machine(); int actual = 31; @@ -55,7 +57,9 @@ public class BoundaryTests //equal, using the equals method List<String> list = new ArrayList<String>(); list.add("MOV R1 -65535"); - list.add("RET R1"); + list.add("MOV R2 1"); + list.add("DIV R3 R1 R2"); + list.add("RET R3"); Machine machine = new Machine(); int actual = -65535; assertEquals(machine.execute(list), actual); @@ -67,9 +71,11 @@ public class BoundaryTests //equal, using the equals method List<String> list = new ArrayList<String>(); list.add("MOV R1 65535"); - list.add("RET R1"); + list.add("MOV R2 1"); + list.add("SUB R3 R1 R2"); + list.add("RET R3"); Machine machine = new Machine(); - int actual = 65535; + int actual = 65534; assertEquals(machine.execute(list), actual); } @@ -102,10 +108,10 @@ public class BoundaryTests @Test public void B13TestCase() { List<String> list = new ArrayList<String>(); - list.add("MOV R1 0"); + list.add("MOV R1 65535"); list.add("MOV R2 100"); - list.add("STR R1 0 R2"); - list.add("LDR R3 R1 0"); + list.add("STR R1 -65535 R2"); + list.add("LDR R3 R1 -65535"); list.add("RET R3"); Machine machine = new Machine(); int actual = 100; @@ -115,10 +121,10 @@ public class BoundaryTests @Test public void B14TestCase() { List<String> list = new ArrayList<String>(); - list.add("MOV R1 60000"); + list.add("MOV R1 -65535"); list.add("MOV R2 100"); - list.add("STR R1 5535 R2"); - list.add("LDR R3 R1 5535"); + list.add("STR R1 65535 R2"); + list.add("LDR R3 R1 65535"); list.add("RET R3"); Machine machine = new Machine(); int actual = 100; @@ -128,32 +134,96 @@ public class BoundaryTests @Test public void B15TestCase() { List<String> list = new ArrayList<String>(); - list.add("MOV R3 0"); - list.add("MOV R1 0"); + list.add("MOV R1 65535"); list.add("MOV R2 100"); - list.add("STR R1 -1 R2");// instruction does nothing - list.add("LDR R3 R1 -1");// instruction does nothing + list.add("STR R1 0 R2");// instruction does nothing + list.add("LDR R3 R1 0");// instruction does nothing list.add("RET R3"); Machine machine = new Machine(); - int actual = 0; + int actual = 100; assertEquals(machine.execute(list), actual); } @Test public void B16TestCase() { List<String> list = new ArrayList<String>(); - list.add("MOV R3 2"); - list.add("MOV R1 60000"); + list.add("MOV R1 0"); list.add("MOV R2 100"); - list.add("STR R1 5536 R2");// instruction does nothing - list.add("LDR R3 R1 5536");// instruction does nothing + list.add("STR R1 65535 R2");// instruction does nothing + list.add("LDR R3 R1 65535");// instruction does nothing list.add("RET R3"); Machine machine = new Machine(); - int actual = 2; + int actual = 100; + assertEquals(machine.execute(list), actual); + } + + @Test public void B17TestCase() +{ + List<String> list = new ArrayList<String>(); + list.add("MOV R1 65534"); + list.add("MOV R2 100"); + list.add("MOV R3 333"); + list.add("STR R1 -65535 R2");// instruction does nothing + list.add("LDR R3 R1 -65535");// instruction does nothing + list.add("RET R3"); + Machine machine = new Machine(); + int actual = 333; + assertEquals(machine.execute(list), actual); +} + + @Test public void B18TestCase() + { + List<String> list = new ArrayList<String>(); + list.add("MOV R1 -65535"); + list.add("MOV R2 100"); + list.add("MOV R3 333"); + list.add("STR R1 65534 R2");// instruction does nothing + list.add("LDR R3 R1 65534");// instruction does nothing + list.add("RET R3"); + Machine machine = new Machine(); + int actual = 333; + assertEquals(machine.execute(list), actual); + } + + @Test public void B19TestCase() + { + List<String> list = new ArrayList<String>(); + list.add("MOV R1 65535"); + list.add("MOV R2 100"); + list.add("MOV R3 333"); + list.add("STR R1 1 R2");// instruction does nothing + list.add("LDR R3 R1 1");// instruction does nothing + list.add("RET R3"); + Machine machine = new Machine(); + int actual = 333; + assertEquals(machine.execute(list), actual); + } + + @Test public void B20TestCase() + { + List<String> list = new ArrayList<String>(); + list.add("MOV R1 1"); + list.add("MOV R2 100"); + list.add("MOV R3 333"); + list.add("STR R1 65535 R2");// instruction does nothing + list.add("LDR R3 R1 65535");// instruction does nothing + list.add("RET R3"); + Machine machine = new Machine(); + int actual = 333; assertEquals(machine.execute(list), actual); } //------------------------------- //To test an exception, specify the expected exception after the @Test + + @Test(expected = NoReturnValueException.class) + public void B0anNoReturnValueExceptionTest() + { + List<String> list = new ArrayList<String>(); + list.add(""); //EMPTY LIST + Machine machine = new Machine(); + machine.execute(list); + } + @Test(expected = InvalidInstructionException.class) public void B3anInvalidInstructionExceptionTest() { @@ -218,16 +288,6 @@ public class BoundaryTests } //To test an exception, specify the expected exception after the @Test - @Test(expected = InvalidInstructionException.class) - public void EC3anInvalidInstructionException() - { - List<String> list = new ArrayList<String>(); - list.add("CMP R1 R2"); - Machine machine = new Machine(); - machine.execute(list); - } - - //Read in a file containing a program and convert into a list of