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

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
Show changes
Commits on Source (23)
......@@ -198,7 +198,7 @@ public class Machine
toks = inst.split("\\s+");
/* check minimum number of tokens */
if (toks.length < 2){
if (false){
throw new InvalidInstructionException();
}
......
......@@ -201,9 +201,8 @@ public class Machine
if (toks.length < 2){
throw new InvalidInstructionException();
}
if (toks[0].equals(INSTRUCTION_ADD)){
if (toks.length != 4){
if (toks.length < 4){
throw new InvalidInstructionException();
}
int rd = parseReg(toks[1]);
......
......@@ -140,7 +140,7 @@ public class Machine
private void validate_reg(int reg)
throws InvalidInstructionException
{
if (reg < 0 || reg > MAX_REG) {
if (reg <= 0 || reg >= MAX_REG) {
throw new InvalidInstructionException();
}
}
......
......@@ -276,7 +276,7 @@ public class Machine
int ra = parseReg(toks[1]);
int offs = parseOffset(toks[2]);
if (regs[ra] == 0){
pc = pc + offs;
pc = pc + abs(offs);
}else{
pc = pc + 1;
}
......
......@@ -278,7 +278,7 @@ public class Machine
if (regs[ra] == 0){
pc = pc + offs;
}else{
pc = pc + 1;
pc = pc;
}
count++;
continue; /* avoid default increment the pc below */
......
......@@ -24,51 +24,68 @@ public class BoundaryTests
{
}
//Any method annotation with "@Test" is executed as a test.
@Test public void aTest()
//To test B1 in Machine.
@Test public void b1Test()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
final int expected = 2;
final int actual = 1 + 1;
final int expected = InvalidInstructionException;
final int actual = Machine.execute("R0");
assertEquals(expected, actual);
}
@Test public void anotherTest()
//To test B5 in Machine.
@Test public void b5Test()
{
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
final int expected = InvalidInstructionException;
final int actual = Machine.execute("R0");
assertEquals(expected, actual);
}
//the assertTrue method is used to check whether something holds.
assertTrue(list.contains("a"));
//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);
}
//Test test opens a file and executes the machine
@Test public void aFileOpenTest()
//To test B7 in Machine.
@Test public void b7Test()
{
final List<String> lines = readInstructions("examples/array.s");
Machine m = new Machine();
assertEquals(m.execute(lines), 45);
final int expected = 0;
final int actual = Machine.execute({LDR R2 R0 1, RET R2});
assertEquals(expected, actual);
}
//To test an exception, specify the expected exception after the @Test
@Test(expected = java.io.IOException.class)
public void anExceptionTest()
throws Throwable
//To test B8 in Machine.
@Test public void b8Test()
{
throw new java.io.IOException();
final int expected = InvalidInstructionException;
final int actual = Machine.execute({LDR R2 R0 32, RET R2});
assertEquals(expected, actual);
}
//This test should fail.
//To provide additional feedback when a test fails, an error message
//can be included
@Test public void aFailedTest()
//To test B9 in Machine.
@Test public void b9Test()
{
//include a message for better feedback
final int expected = 2;
final int actual = 1 + 2;
assertEquals("Some failure message", expected, actual);
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
......
......@@ -24,51 +24,100 @@ public class PartitioningTests
{
}
//Any method annotation with "@Test" is executed as a test.
@Test public void aTest()
//To test EC5 in Machine.
@Test public void ec5Test()
{
//the assertEquals method used to check whether two values are
//equal, using the equals method
final int expected = 2;
final int actual = 1 + 1;
final int expected = 0;
final int actual = Machine.execute("RET R0 R1");
assertEquals(expected, actual);
}
@Test public void anotherTest()
//To test EC6 in Machine.
@Test public void ec6Test()
{
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
final int expected = NoReturnValueException;
final int actual = Machine.execute({MOV R0 1, MOV R1 1, ADD R2 R0 R1});
assertEquals(expected, actual);
}
//To test EC7 in Machine.
@Test public void ec7Test()
{
final int expected = 0;
final int actual = Machine.execute({ADD R2 R0 R1, RET R2});
assertEquals(expected, actual);
}
//To test EC8 in Machine.
@Test public void ec8Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({ADD R2 R0 R32, RET R2});
assertEquals(expected, actual);
}
//the assertTrue method is used to check whether something holds.
assertTrue(list.contains("a"));
//To test EC9 in Machine.
@Test public void ec9Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({ADD R2 R0, RET R2});
assertEquals(expected, actual);
}
//Test test opens a file and executes the machine
@Test public void aFileOpenTest()
//To test EC11 in Machine.
@Test public void ec11Test()
{
final List<String> lines = readInstructions("examples/array.s");
Machine m = new Machine();
assertEquals(m.execute(lines), 45);
final int expected = InvalidInstructionException;
final int actual = Machine.execute({LDR R2 R0 -1, RET R2});
assertEquals(expected, actual);
}
//To test an exception, specify the expected exception after the @Test
@Test(expected = java.io.IOException.class)
public void anExceptionTest()
throws Throwable
//To test EC13 in Machine.
@Test public void ec13Test()
{
throw new java.io.IOException();
final int expected = InvalidInstructionException;
final int actual = Machine.execute({LDR R2 R0 32, RET R2});
assertEquals(expected, actual);
}
//This test should fail.
//To provide additional feedback when a test fails, an error message
//can be included
@Test public void aFailedTest()
//To test EC18 in Machine.
@Test public void ec18Test()
{
//include a message for better feedback
final int expected = 2;
final int actual = 1 + 2;
assertEquals("Some failure message", expected, actual);
final int expected = InvalidInstructionException;
final int actual = Machine.execute({JMP -65536, RET R0});
assertEquals(expected, actual);
}
//To test EC20 in Machine.
@Test public void ec20Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({JMP 65536, RET R0});
assertEquals(expected, actual);
}
//To test EC21 in Machine.
@Test public void ec21Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({JMP abc, RET R0});
assertEquals(expected, actual);
}
//To test EC22 in Machine.
@Test public void ec22Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({RET R0, RET R1});
assertEquals(expected, actual);
}
//To test EC23 in Machine.
@Test public void ec23Test()
{
final int expected = InvalidInstructionException;
final int actual = Machine.execute({R0});
assertEquals(expected, actual);
}
//Read in a file containing a program and convert into a list of
......