From c8842fe8901816eae133dd32ba91a213a50e5621 Mon Sep 17 00:00:00 2001 From: Jiaming Zhang <jiamingz3@student.unimelb.edu.au> Date: Sat, 1 Sep 2018 16:29:00 +1000 Subject: [PATCH] Upload New File --- test/swen90006/machine/BoundaryTests.java | 117 ++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 test/swen90006/machine/BoundaryTests.java diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java new file mode 100644 index 0000000..a1aef89 --- /dev/null +++ b/test/swen90006/machine/BoundaryTests.java @@ -0,0 +1,117 @@ +package swen90006.machine; + +import java.util.List; +import java.util.ArrayList; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Files; +import java.nio.file.FileSystems; + +import org.junit.*; +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() + { + } + + //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() + { + } + + //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); + } + + //To test B1 in Machine. + @Test public void b1Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute("R0"); + assertEquals(expected, actual); + } + + //To test B5 in Machine. + @Test public void b5Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute("R0"); + assertEquals(expected, actual); + } + + //To test B6 in Machine. + @Test public void b6Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute({“LDR R2 R0 -1”, “RET R2”}); + assertEquals(expected, actual); + } + + //To test B7 in Machine. + @Test public void b7Test() + { + final int expected = 0; + final int actual = Machine.execute({“LDR R2 R0 1”, “RET R2”}); + assertEquals(expected, actual); + } + + //To test B8 in Machine. + @Test public void b8Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute({“LDR R2 R0 32”, “RET R2”}); + assertEquals(expected, actual); + } + + //To test B9 in Machine. + @Test public void b9Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute({“MOV R2 -65536”, “RET R2”}); + assertEquals(expected, actual); + } + + //To test B10 in Machine. + @Test public void b10Test() + { + final int expected = 1; + final int actual = Machine.execute({“MOV R2 1”, “RET R2”}); + assertEquals(expected, actual); + } + + //To test B11 in Machine. + @Test public void b11Test() + { + final int expected = InvalidInstructionException; + final int actual = Machine.execute({“MOV R2 65536”, “RET R2”}); + assertEquals(expected, actual); + } + + //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; + } +} -- GitLab