From 910cb5daf9857443eedc7f8a4ed48d53ff45a96d Mon Sep 17 00:00:00 2001 From: Jinge Zhang <j.zhang198@student.unimelb.edu.au> Date: Tue, 4 Sep 2018 22:15:56 +1000 Subject: [PATCH] Replace BoundaryTests.java --- test/swen90006/machine/BoundaryTests.java | 244 ++++++++++++++++------ 1 file changed, 176 insertions(+), 68 deletions(-) diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 61ce1ca..7e10a75 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -12,79 +12,187 @@ import static org.junit.Assert.*; public class BoundaryTests { - //Any method annotated with "@Before" will be executed before each test, - //allowing the tester to set up some shared resources. - @Before public void setUp() - { - } + @Test + public void test1() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("MOV R0 3"); + list.add("MOV R1 1"); + list.add("DIV R2 R0 R1"); + list.add("RET R2"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(3, m.execute(list)); + } - //Any method annotated with "@After" will be executed after each test, - //allowing the tester to release any shared resources used in the setup. - @After public void tearDown() - { - } + @Test(expected = InvalidInstructionException.class) + public void test2() { + List<String> list = new ArrayList<String>(); + list.add("MOV R33 33"); + list.add("RET R2"); + Machine m = new Machine(); + m.execute(list); + } - //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 = InvalidInstructionException.class) + public void test3() { + List<String> list = new ArrayList<String>(); + list.add("MOV R0 1"); + list.add("JMP 1 1"); + list.add("RET R2"); + Machine m = new Machine(); + m.execute(list); + } - @Test public void anotherTest() - { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); + @Test + public void test4() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("RET R19"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(0, m.execute(list)); + } - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); - } + @Test + public void test5() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("LDR R0 R1 655"); + list.add("RET R0"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(0, m.execute(list)); + } - //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(); - } + @Test(expected = NoReturnValueException.class) + public void test6() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add(""); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(0, m.execute(list)); + } - //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 + public void test7() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("MOV R3 10"); + list.add("MOV R2 1"); + list.add("MOV R1 0"); + list.add("MOV R0 100"); + list.add("SUB R4 R3 R1"); + list.add("JZ R4 5"); + list.add("STR R0 0 R1"); + list.add("ADD R1 R1 R2"); + list.add("ADD R0 R0 R2"); + list.add("JMP -5"); + list.add("MOV R1 0"); + list.add("MOV R0 100"); + list.add("MOV R5 0"); + list.add("SUB R4 R3 R1"); + list.add("JZ R4 6"); + list.add("LDR R4 R0 0"); + list.add("ADD R5 R5 R4"); + list.add("ADD R0 R0 R2"); + list.add("ADD R1 R1 R2"); + list.add("JMP -6"); + list.add("RET R5"); + list.add(""); + list.add(""); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(45, m.execute(list)); + } - //Read in a file containing a program and convert into a list of - //string instructions - 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 test8() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + for (int i = 0; i <= 31; i++) { + String command="MOV R"+i+" 5"; + list.add(command); + } + list.add("RET R0"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(5, m.execute(list)); + } + + @Test(expected = InvalidInstructionException.class) + public void test9() { + List<String> list = new ArrayList<String>(); + list.add("MOV R-1 1"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + m.execute(list); + } + + @Test(expected = InvalidInstructionException.class) + public void test10() { + List<String> list = new ArrayList<String>(); + list.add("MOV R32 1"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + m.execute(list); + } + + @Test(expected = InvalidInstructionException.class) + public void test11() { + List<String> list = new ArrayList<String>(); + list.add("MOV R0 65536"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + m.execute(list); + } + + @Test(expected = InvalidInstructionException.class) + public void test12() { + List<String> list = new ArrayList<String>(); + list.add("MOV R0 -65536"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + m.execute(list); + } + + @Test + public void test13() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("MOV R0 1"); + list.add("MOV R1 10"); + list.add("DIV R1 R0 R2"); + list.add("RET R1"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(10, m.execute(list)); + } + + @Test + public void test14() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("MOV R0 0"); + list.add("JZ R0 2"); + list.add("MOV R0 2"); + list.add("RET R0"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(0, m.execute(list)); + } + + @Test + public void test15() { + /* mutation: regs[src1] +1 */ + List<String> list = new ArrayList<String>(); + list.add("MOV R0 0"); + list.add("MOV R1 -2"); + list.add("LDR R1 R0 -65535"); + list.add("RET R1"); + Machine m = new Machine(); + // the assertTrue method is used to check whether something holds. + assertEquals(-2, m.execute(list)); + } } -- GitLab