Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • tmiller/SWEN90006-A1-2018
  • cbalasuriya/SWEN90006-A1-2018
  • zhangyuny/SWEN90006-A1-2018
  • zhaor4/SWEN90006-A1-2018
  • nelsonc1/SWEN90006-A1-2018
  • jiamingz3/SWEN90006-A1-2018
  • cvidler/SWEN90006-A1-2018
  • 923841/SWEN90006-A1-2018
  • hzhu5/SWEN90006-A1-2018
  • zhuoyaof/SWEN90006-A1-2018
  • haoyangc/SWEN90006-A1-2018
  • austinl/SWEN90006-A1-2018
  • gxuan/SWEN90006-A1-2018
  • zlang/SWEN90006-A1-2018
  • junhany/SWEN90006-A1-2018
  • shibaoz/SWEN90006-A1-2018
  • arwinders/SWEN90006-A1-2018
  • jiankunc/SWEN90006-A1-2018
  • xujiaz/SWEN90006-A1-2018
  • xiaomingz/SWEN90006-A1-2018
  • xixiangw/SWEN90006-A1-2018
  • yunchengw/SWEN90006-A1-2018
  • abdulk/SWEN90006-A1-2018
  • yangz7/SWEN90006-A1-2018
  • linyuanz/SWEN90006-A1-2018
  • zhaolind/SWEN90006-A1-2018
  • jingjiahuil/SWEN90006-A1-2018
  • hongyic3/SWEN90006-A1-2018
  • zhouw4/SWEN90006-A1-2018
  • emilylm/SWEN90006-A1-2018
  • jingez1/SWEN90006-A1-2018
  • minzhex/SWEN90006-A1-2018
32 results
Select Git revision
  • master
1 result
Show changes

Commits on Source 12

...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
</target> </target>
<target name="partitioning" depends="classes"> <target name="partitioning" depends="classes">
<parallel threadCount="1" timeout="5000">
<sequential>
<junit printsummary="yes" fork="yes" haltonfailure="yes"> <junit printsummary="yes" fork="yes" haltonfailure="yes">
<classpath> <classpath>
<pathelement path="classes/"/> <pathelement path="classes/"/>
...@@ -25,9 +27,13 @@ ...@@ -25,9 +27,13 @@
<formatter type="plain"/> <formatter type="plain"/>
<test name="swen90006.machine.PartitioningTests"/> <test name="swen90006.machine.PartitioningTests"/>
</junit> </junit>
</sequential>
</parallel>
</target> </target>
<target name="boundary" depends="classes"> <target name="boundary" depends="classes">
<parallel threadCount="1" timeout="5000">
<sequential>
<junit printsummary="yes" fork="yes" haltonfailure="yes"> <junit printsummary="yes" fork="yes" haltonfailure="yes">
<classpath> <classpath>
<pathelement path="classes/"/> <pathelement path="classes/"/>
...@@ -37,7 +43,8 @@ ...@@ -37,7 +43,8 @@
<formatter type="plain"/> <formatter type="plain"/>
<test name="swen90006.machine.BoundaryTests"/> <test name="swen90006.machine.BoundaryTests"/>
</junit> </junit>
</sequential>
</parallel>
</target> </target>
</project> </project>
...@@ -39,7 +39,7 @@ public class Machine ...@@ -39,7 +39,7 @@ public class Machine
/** jz ra offs =~ if (ra == 0) pc = pc + offs else pc = pc + 1 */ /** jz ra offs =~ if (ra == 0) pc = pc + offs else pc = pc + 1 */
public static final String INSTRUCTION_JZ = "jz"; public static final String INSTRUCTION_JZ = "jz";
public static final int NUM_REGS = 32; public static final int NUM_REGS = 33;
public static final int MAX_REG = (NUM_REGS - 1); public static final int MAX_REG = (NUM_REGS - 1);
public static final int MEMORY_SIZE = 65536; /* 4 x as much memory as a 64 */ public static final int MEMORY_SIZE = 65536; /* 4 x as much memory as a 64 */
public static final int MAX_ADDR = MEMORY_SIZE-1; public static final int MAX_ADDR = MEMORY_SIZE-1;
......
...@@ -106,7 +106,7 @@ public class Machine ...@@ -106,7 +106,7 @@ public class Machine
private int parseReg(String s) throws InvalidInstructionException private int parseReg(String s) throws InvalidInstructionException
{ {
if (s.length() < 2){ if (s.length() < 3){
throw new InvalidInstructionException(); throw new InvalidInstructionException();
} }
if (s.charAt(0) != 'r'){ if (s.charAt(0) != 'r'){
......
...@@ -170,7 +170,7 @@ public class Machine ...@@ -170,7 +170,7 @@ public class Machine
int pc = 0; int pc = 0;
final int progLength = instructions.size(); final int progLength = instructions.size();
while(true){ while(true){
if (pc < 0 || pc >= progLength){ if (pc < 0 && pc >= progLength){
/* will cause NoReturnValueException to be thrown /* will cause NoReturnValueException to be thrown
* but that is not a bug and and indeed is what the * but that is not a bug and and indeed is what the
* VM is supposed to do if the pc becomes negative, * VM is supposed to do if the pc becomes negative,
......
...@@ -167,7 +167,7 @@ public class Machine ...@@ -167,7 +167,7 @@ public class Machine
{ {
int instructionsExecuted = 0; int instructionsExecuted = 0;
int pc = 0; int pc = 1;
final int progLength = instructions.size(); final int progLength = instructions.size();
while(true){ while(true){
if (pc < 0 || pc >= progLength){ if (pc < 0 || pc >= progLength){
......
...@@ -10,81 +10,249 @@ import java.nio.file.FileSystems; ...@@ -10,81 +10,249 @@ import java.nio.file.FileSystems;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class BoundaryTests public class BoundaryTests {
{ // // Any method annotated with "@Before" will be executed before each test,
//Any method annotated with "@Before" will be executed before each test, // // allowing the tester to set up some shared resources.
//allowing the tester to set up some shared resources. // @Before
@Before public void setUp() // public void setUp() {
{ // }
} //
// // Any method annotated with "@After" will be executed after each test,
//Any method annotated with "@After" will be executed after each test, // // allowing the tester to release any shared resources used in the setup.
//allowing the tester to release any shared resources used in the setup. // @After
@After public void tearDown() // public void tearDown() {
{ // }
} //
// // Any method annotation with "@Test" is executed as a test.
//Any method annotation with "@Test" is executed as a test. // @Test
@Test public void aTest() // public void aTest() {
{ // // the assertEquals method used to check whether two values are
//the assertEquals method used to check whether two values are // // equal, using the equals method
//equal, using the equals method // final int expected = 2;
final int expected = 2; // final int actual = 1 + 1;
final int actual = 1 + 1; // assertEquals(expected, actual);
assertEquals(expected, actual); // }
} //
// @Test
@Test public void anotherTest() // public void anotherTest() {
{ // List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<String>(); // list.add("a");
list.add("a"); // list.add("b");
list.add("b"); //
// // the assertTrue method is used to check whether something holds.
//the assertTrue method is used to check whether something holds. // assertTrue(list.contains("a"));
assertTrue(list.contains("a")); // }
} //
// // Test test opens a file and executes the machine
//Test test opens a file and executes the machine // @Test
@Test public void aFileOpenTest() // public void aFileOpenTest() {
{ // final List<String> lines = readInstructions("examples/array.s");
final List<String> lines = readInstructions("examples/array.s"); // Machine m = new Machine();
Machine m = new Machine(); // assertEquals(m.execute(lines), 45);
assertEquals(m.execute(lines), 45); // }
} //
// // To test an exception, specify the expected exception after the @Test
//To test an exception, specify the expected exception after the @Test // @Test(expected = java.io.IOException.class)
@Test(expected = java.io.IOException.class) // public void anExceptionTest() throws Throwable {
public void anExceptionTest() // throw new java.io.IOException();
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
//This test should fail. // @Test
//To provide additional feedback when a test fails, an error message // public void aFailedTest() {
//can be included // // include a message for better feedback
@Test public void aFailedTest() // final int expected = 2;
{ // final int actual = 1 + 2;
//include a message for better feedback // assertEquals("Some failure message", expected, actual);
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) {
//Read in a file containing a program and convert into a list of // Charset charset = Charset.forName("UTF-8");
//string instructions // List<String> lines = null;
private List<String> readInstructions(String file) // try {
{ // lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset);
Charset charset = Charset.forName("UTF-8"); // } catch (Exception e) {
List<String> lines = null; // System.err.println("Invalid input file! (stacktrace follows)");
try { // e.printStackTrace(System.err);
lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); // System.exit(1);
} // }
catch (Exception e){ // return lines;
System.err.println("Invalid input file! (stacktrace follows)"); // }
e.printStackTrace(System.err);
System.exit(1); // Tests the off point for Register < 0
} @Test(expected = InvalidInstructionException.class)
return lines; public void EC1() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("add R-1 R0");
machine.execute(instruction);
}
// Tests the off point for Register > 31
@Test(expected = InvalidInstructionException.class)
public void EC2() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("sub R32 R0");
machine.execute(instruction);
}
// Tests the off point for val < -65535
@Test(expected = InvalidInstructionException.class)
public void EC3() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("mov R0 -65536");
machine.execute(instruction);
}
// Tests the off point for val > 65535
@Test(expected = InvalidInstructionException.class)
public void EC4() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ldr R0 R1 65536");
machine.execute(instruction);
}
// Tests the on point for Register < 0 and Last command == "RET"
@Test
public void EC5_OnPointRegisterLessThanMin() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ret R0");
assertEquals(machine.execute(instruction), 0);
}
// Tests the on point for Register > 31 and Last command == "RET"
@Test
public void EC5_OnPointRegisterGreaterThanMax() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ret R31");
assertEquals(machine.execute(instruction), 0);
}
// Test on point for val < -65535, Register < 0 and off point for Last command == "RET"
@Test(expected = NoReturnValueException.class)
public void EC6_OnPointValLessThanMin() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("str R0 -65535 R1");
machine.execute(instruction);
}
// Test on point for val > 65535, Register > 31 and off point for Last command == "RET"
@Test(expected = NoReturnValueException.class)
public void EC6_OnPointValGreaterThanMax() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("jz R31 65535");
machine.execute(instruction);
}
// Tests the off point for Register < 0
@Test(expected = InvalidInstructionException.class)
public void EC7() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("div R-1 R0 R1");
instruction.add("ret R0");
machine.execute(instruction);
}
// Tests the off point for Register > 31
@Test(expected = InvalidInstructionException.class)
public void EC8() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("jmp 1");
instruction.add("ret R32");
machine.execute(instruction);
}
// Test off point for val < -65535
@Test(expected = InvalidInstructionException.class)
public void EC9() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("jz R0 -65536");
instruction.add("ret R0");
machine.execute(instruction);
}
// Test off point for val > 65535
@Test(expected = InvalidInstructionException.class)
public void EC10() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("mov R0 65536");
instruction.add("jz R0 1");
instruction.add("ret R0");
machine.execute(instruction);
}
// Test on points for Register < 0, Register > 31, val < -65535, val > 65535 and Last command == "RET"
@Test
public void EC11() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("mov R0 -65535");
instruction.add("mov R31 65535");
instruction.add("MUL R1 R0 R31");
instruction.add("ret R31");
assertEquals(machine.execute(instruction), 65535);
}
// Test on point for Register < 0, Register > 31, val < -65535, val > 65535 and off point for Last command == "RET"
@Test(expected = NoReturnValueException.class)
public void EC12() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("mov R0 -65535");
instruction.add("mov R31 65535");
instruction.add("jmp -5");
machine.execute(instruction);
}
// Test on point for wrong syntax
@Test(expected = InvalidInstructionException.class)
public void EC13_On() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("");
instruction.add("abc");
machine.execute(instruction);
}
// Test off point for wrong syntax
@Test
public void EC13_Off() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ret R0");
machine.execute(instruction);
assertEquals(machine.execute(instruction), 0);
}
// Test on point for list length == 0
@Test(expected = NoReturnValueException.class)
public void EC14_On() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
machine.execute(instruction);
}
// Test off point for list length == 0
@Test(expected = InvalidInstructionException.class)
public void EC14_Off() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ABC AA");
machine.execute(instruction);
} }
} }
...@@ -8,83 +8,132 @@ import java.nio.file.Files; ...@@ -8,83 +8,132 @@ import java.nio.file.Files;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import org.junit.*; import org.junit.*;
import com.sun.xml.internal.ws.util.StringUtils;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class PartitioningTests public class PartitioningTests {
{
//Any method annotated with "@Before" will be executed before each test, @Test(expected = InvalidInstructionException.class)
//allowing the tester to set up some shared resources. public void EC1() throws Throwable {
@Before public void setUp() Machine machine = new Machine();
{ List<String> instruction = new ArrayList<>();
instruction.add("add R-1 R0");
machine.execute(instruction);
}
@Test(expected = InvalidInstructionException.class)
public void EC2() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("sub R32 R0");
machine.execute(instruction);
}
@Test(expected = InvalidInstructionException.class)
public void EC3() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("mov R0 -65536");
machine.execute(instruction);
}
@Test(expected = InvalidInstructionException.class)
public void EC4() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("ldr R0 R1 65536");
machine.execute(instruction);
} }
//Any method annotated with "@After" will be executed after each test, @Test
//allowing the tester to release any shared resources used in the setup. public void EC5() {
@After public void tearDown() Machine machine = new Machine();
{ List<String> instruction = new ArrayList<>();
instruction.add("ret R0");
assertEquals(machine.execute(instruction), 0);
} }
//Any method annotation with "@Test" is executed as a test. @Test(expected = NoReturnValueException.class)
@Test public void aTest() public void EC6() throws Throwable {
{ Machine machine = new Machine();
//the assertEquals method used to check whether two values are List<String> instruction = new ArrayList<>();
//equal, using the equals method instruction.add("jmp -1");
final int expected = 2; machine.execute(instruction);
final int actual = 1 + 1;
assertEquals(expected, actual);
} }
@Test public void anotherTest() @Test(expected = InvalidInstructionException.class)
{ public void EC7() throws Throwable {
List<String> list = new ArrayList<String>(); Machine machine = new Machine();
list.add("a"); List<String> instruction = new ArrayList<>();
list.add("b"); instruction.add("div R-1 R0 R1");
instruction.add("ret R0");
machine.execute(instruction);
}
//the assertTrue method is used to check whether something holds. @Test(expected = InvalidInstructionException.class)
assertTrue(list.contains("a")); public void EC8() throws Throwable {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("str R32 1 R0");
instruction.add("ret R0");
machine.execute(instruction);
} }
//Test test opens a file and executes the machine @Test(expected = InvalidInstructionException.class)
@Test public void aFileOpenTest() public void EC9() throws Throwable {
{ Machine machine = new Machine();
final List<String> lines = readInstructions("examples/array.s"); List<String> instruction = new ArrayList<>();
Machine m = new Machine(); instruction.add("jz R0 -65536");
assertEquals(m.execute(lines), 45); instruction.add("ret R0");
machine.execute(instruction);
} }
//To test an exception, specify the expected exception after the @Test @Test(expected = InvalidInstructionException.class)
@Test(expected = java.io.IOException.class) public void EC10() throws Throwable {
public void anExceptionTest() Machine machine = new Machine();
throws Throwable List<String> instruction = new ArrayList<>();
{ instruction.add("mov R0 65536");
throw new java.io.IOException(); instruction.add("jz R0 1");
instruction.add("ret R0");
machine.execute(instruction);
} }
//This test should fail. @Test
//To provide additional feedback when a test fails, an error message public void EC11() {
//can be included Machine machine = new Machine();
@Test public void aFailedTest() List<String> instruction = new ArrayList<>();
{ instruction.add("mov R0 -65535");
//include a message for better feedback instruction.add("mov R31 65535");
final int expected = 2; instruction.add("mul R1 R0 R31");
final int actual = 1 + 2; instruction.add("ret R0");
assertEquals("Some failure message", expected, actual); assertEquals(machine.execute(instruction), -65535);
} }
//Read in a file containing a program and convert into a list of @Test(expected = NoReturnValueException.class)
//string instructions public void EC12() {
private List<String> readInstructions(String file) Machine machine = new Machine();
{ List<String> instruction = new ArrayList<>();
Charset charset = Charset.forName("UTF-8"); instruction.add("mov R0 -65535");
List<String> lines = null; instruction.add("mov R31 65535");
try { instruction.add("jmp 2");
lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); machine.execute(instruction);
} }
catch (Exception e){
System.err.println("Invalid input file! (stacktrace follows)"); @Test(expected = InvalidInstructionException.class)
e.printStackTrace(System.err); public void EC13() {
System.exit(1); Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
instruction.add("");
instruction.add("abc");
machine.execute(instruction);
} }
return lines;
@Test(expected = NoReturnValueException.class)
public void EC14() {
Machine machine = new Machine();
List<String> instruction = new ArrayList<>();
machine.execute(instruction);
} }
} }