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
Loading items

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
Loading items
Show changes

Commits on Source 23

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