diff --git a/examples/add.s b/examples/add.s new file mode 100644 index 0000000000000000000000000000000000000000..ea53133b968dad6c6e3d7a48119056b0d15511d7 --- /dev/null +++ b/examples/add.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R2 4; +ADD R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/addlong.s b/examples/addlong.s new file mode 100644 index 0000000000000000000000000000000000000000..ba98bbd9c2031776b8e15cc7d6b0c76ce77b8d67 --- /dev/null +++ b/examples/addlong.s @@ -0,0 +1,5 @@ +MOV R1 3; +MOV R2 4; +MOV R3 5; +ADD R0 R1 R2 R3; +RET R0; \ No newline at end of file diff --git a/examples/addshort.s b/examples/addshort.s new file mode 100644 index 0000000000000000000000000000000000000000..e89f4c9a436e4d62d239833e50e28a95dd696fa2 --- /dev/null +++ b/examples/addshort.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R2 4; +ADD R0 R1; +RET R0; \ No newline at end of file diff --git a/examples/blankline.s b/examples/blankline.s new file mode 100644 index 0000000000000000000000000000000000000000..9aa3f4d3189a8996bbdab316d35f8a0a99a6f891 --- /dev/null +++ b/examples/blankline.s @@ -0,0 +1,7 @@ +MOV R1 3; + + +MOV R2 4; +ADD R0 R1 R2; + +RET R0; \ No newline at end of file diff --git a/examples/div.s b/examples/div.s new file mode 100644 index 0000000000000000000000000000000000000000..02c9e57089458d8c3b42be34c48960f4f90ff33a --- /dev/null +++ b/examples/div.s @@ -0,0 +1,4 @@ +MOV R1 12; +MOV R2 5; +DIV R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/divlong.s b/examples/divlong.s new file mode 100644 index 0000000000000000000000000000000000000000..6e7bee5fa2e0c1bf2479d3e656b0b4ce5623ac7b --- /dev/null +++ b/examples/divlong.s @@ -0,0 +1,5 @@ +MOV R1 12; +MOV R2 5; +MOV R3 2; +DIV R0 R1 R2 R3; +RET R0; \ No newline at end of file diff --git a/examples/divshort.s b/examples/divshort.s new file mode 100644 index 0000000000000000000000000000000000000000..4281660c9d97400a1d0dfe257965eabec65aa714 --- /dev/null +++ b/examples/divshort.s @@ -0,0 +1,4 @@ +MOV R1 12; +MOV R2 5; +DIV R0 R1; +RET R0; \ No newline at end of file diff --git a/examples/divzero.s b/examples/divzero.s new file mode 100644 index 0000000000000000000000000000000000000000..c8826fcb94838838b54b5311eef0f3c99879d258 --- /dev/null +++ b/examples/divzero.s @@ -0,0 +1,5 @@ +MOV R0 17; +MOV R1 12; +MOV R2 0; +DIV R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/empty.s b/examples/empty.s new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/examples/intlarge.s b/examples/intlarge.s new file mode 100644 index 0000000000000000000000000000000000000000..d75d8c60f1243fb2458b36034d86443122b0b86e --- /dev/null +++ b/examples/intlarge.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 65536; +RET R0; \ No newline at end of file diff --git a/examples/intmax.s b/examples/intmax.s new file mode 100644 index 0000000000000000000000000000000000000000..abb465f3931d7976852abf7c9fba36684ba413bf --- /dev/null +++ b/examples/intmax.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 65535; +RET R0; \ No newline at end of file diff --git a/examples/intmin.s b/examples/intmin.s new file mode 100644 index 0000000000000000000000000000000000000000..43b3b6be69a18e1a0d30b62533e0f69c42413e51 --- /dev/null +++ b/examples/intmin.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 -65535; +RET R0; \ No newline at end of file diff --git a/examples/intsmall.s b/examples/intsmall.s new file mode 100644 index 0000000000000000000000000000000000000000..48c91ab56a4f69341f16402c3feab3d4a8f9a208 --- /dev/null +++ b/examples/intsmall.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 -65536; +RET R0; \ No newline at end of file diff --git a/examples/invalidcommand.s b/examples/invalidcommand.s new file mode 100644 index 0000000000000000000000000000000000000000..a00b6975c25d5f859e362e3b6d29033fa4744b1b --- /dev/null +++ b/examples/invalidcommand.s @@ -0,0 +1,2 @@ +ADR R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/invalidregister.s b/examples/invalidregister.s new file mode 100644 index 0000000000000000000000000000000000000000..efc103c53b7beb84bb336f045ccd39c0a63adae3 --- /dev/null +++ b/examples/invalidregister.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R32 4; +ADD R0 R1 R32; +RET R0; \ No newline at end of file diff --git a/examples/invalidregister2.s b/examples/invalidregister2.s new file mode 100644 index 0000000000000000000000000000000000000000..83f59eb3bdfa156fdc56ff96ee35b6fc4d2433e4 --- /dev/null +++ b/examples/invalidregister2.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R32 4; +ADD R0 R1 15; +RET R0; \ No newline at end of file diff --git a/examples/jmp.s b/examples/jmp.s new file mode 100644 index 0000000000000000000000000000000000000000..45bc56bc1462e9d4a0df1efc27f6e114d8e73c1c --- /dev/null +++ b/examples/jmp.s @@ -0,0 +1,4 @@ +MOV R0 5 +JMP 2 +MOV R0 3 +RET R0 \ No newline at end of file diff --git a/examples/jmpbackjump.s b/examples/jmpbackjump.s new file mode 100644 index 0000000000000000000000000000000000000000..7032f2bccb776f27439dbf6534a982d65814c285 --- /dev/null +++ b/examples/jmpbackjump.s @@ -0,0 +1,4 @@ +MOV R0 5 +JMP -2 +MOV R0 3 +RET R0 \ No newline at end of file diff --git a/examples/jmpfwdjump.s b/examples/jmpfwdjump.s new file mode 100644 index 0000000000000000000000000000000000000000..c03edc72465df07a6e76efe4fbc27e105af0f3b3 --- /dev/null +++ b/examples/jmpfwdjump.s @@ -0,0 +1,4 @@ +MOV R0 5 +JMP 3 +MOV R0 3 +RET R0 \ No newline at end of file diff --git a/examples/jmplong.s b/examples/jmplong.s new file mode 100644 index 0000000000000000000000000000000000000000..10c950031fc37fbe1e1919283d6496bb8cfa8334 --- /dev/null +++ b/examples/jmplong.s @@ -0,0 +1,4 @@ +MOV R0 5 +JMP 2 3 +MOV R0 3 +RET R0 \ No newline at end of file diff --git a/examples/jmpshort.s b/examples/jmpshort.s new file mode 100644 index 0000000000000000000000000000000000000000..87a502156d8e41136b401876cffc71a21bdd9474 --- /dev/null +++ b/examples/jmpshort.s @@ -0,0 +1,4 @@ +MOV R0 5 +JMP +MOV R0 3 +RET R0 \ No newline at end of file diff --git a/examples/jz.s b/examples/jz.s new file mode 100644 index 0000000000000000000000000000000000000000..093880bb2be12f237b376a8c9e798e9269ed0d10 --- /dev/null +++ b/examples/jz.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0 2; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzback.s b/examples/jzback.s new file mode 100644 index 0000000000000000000000000000000000000000..ec0c9eef93a8f27d6a073cc0c93e6e67216a3003 --- /dev/null +++ b/examples/jzback.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0 -2; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzfwd.s b/examples/jzfwd.s new file mode 100644 index 0000000000000000000000000000000000000000..236af9f4f94b85837a86e86d2b72d2022b72ab83 --- /dev/null +++ b/examples/jzfwd.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0 3; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzlong.s b/examples/jzlong.s new file mode 100644 index 0000000000000000000000000000000000000000..eb804a5d77a77527b6367f1a2b13a76c235884b3 --- /dev/null +++ b/examples/jzlong.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0 2 3; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzmax.s b/examples/jzmax.s new file mode 100644 index 0000000000000000000000000000000000000000..093880bb2be12f237b376a8c9e798e9269ed0d10 --- /dev/null +++ b/examples/jzmax.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0 2; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jznotzero.s b/examples/jznotzero.s new file mode 100644 index 0000000000000000000000000000000000000000..0f500c798625cd8ee64a224b8e16de730f4fc158 --- /dev/null +++ b/examples/jznotzero.s @@ -0,0 +1,4 @@ +MOV R0 1; +JZ R0 2; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzshort.s b/examples/jzshort.s new file mode 100644 index 0000000000000000000000000000000000000000..bc8aeb46fe382d7845123b940a2ff1bdd015121e --- /dev/null +++ b/examples/jzshort.s @@ -0,0 +1,4 @@ +MOV R0 0; +JZ R0; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/jzzero.s b/examples/jzzero.s new file mode 100644 index 0000000000000000000000000000000000000000..4951d92c1ad367d3fb1007651a308f362c7fe377 --- /dev/null +++ b/examples/jzzero.s @@ -0,0 +1,7 @@ +MOV R0 5 +MOV R1 1 +JZ R0 4 +ADD R5 R5 R0 +SUB R0 R0 R1 +JMP -3 +RET R5 \ No newline at end of file diff --git a/examples/ldrlong.s b/examples/ldrlong.s new file mode 100644 index 0000000000000000000000000000000000000000..e924051c5ec2ffc1bbd0c3e50cd19fa6c21e59fd --- /dev/null +++ b/examples/ldrlong.s @@ -0,0 +1,6 @@ +MOV R0 13; +MOV R1 60; +STR R1 15 R0; +MOV R2 37; +LDR R3 R2 R0 38; +RET R3; \ No newline at end of file diff --git a/examples/ldrshort.s b/examples/ldrshort.s new file mode 100644 index 0000000000000000000000000000000000000000..494695ef8385d487e2330bd9f077ba4ccd61e9a8 --- /dev/null +++ b/examples/ldrshort.s @@ -0,0 +1,6 @@ +MOV R0 13; +MOV R1 60; +STR R1 15 R0; +MOV R2 37; +LDR R3 38; +RET R3; \ No newline at end of file diff --git a/examples/ldrstr.s b/examples/ldrstr.s new file mode 100644 index 0000000000000000000000000000000000000000..0e51171fbaf7ed14ecf24c72e3020ed06bfe526e --- /dev/null +++ b/examples/ldrstr.s @@ -0,0 +1,6 @@ +MOV R0 13; +MOV R1 60; +STR R1 15 R0; +MOV R2 37; +LDR R3 R2 38; +RET R3; \ No newline at end of file diff --git a/examples/ldrstrbig.s b/examples/ldrstrbig.s new file mode 100644 index 0000000000000000000000000000000000000000..dd9c141076e11f226f9e44b4c496b9572ba68020 --- /dev/null +++ b/examples/ldrstrbig.s @@ -0,0 +1,5 @@ +MOV R0 15; +MOV R1 65536; +STR R1 15 R0; +LDR R2 R1 0; +RET R2; \ No newline at end of file diff --git a/examples/ldrstrmax.s b/examples/ldrstrmax.s new file mode 100644 index 0000000000000000000000000000000000000000..4abe58622e7e6d6a4b2e201d0d3153348bc1687f --- /dev/null +++ b/examples/ldrstrmax.s @@ -0,0 +1,5 @@ +MOV R0 15; +MOV R1 65535; +STR R1 15 R0; +LDR R2 R1 0; +RET R2; \ No newline at end of file diff --git a/examples/ldrstrmin.s b/examples/ldrstrmin.s new file mode 100644 index 0000000000000000000000000000000000000000..6cc76cabdfce10cbc34382f7f9a974f8e24f0176 --- /dev/null +++ b/examples/ldrstrmin.s @@ -0,0 +1,5 @@ +MOV R0 15; +MOV R1 -65535; +STR R1 15 R0; +LDR R2 R1 0; +RET R2; \ No newline at end of file diff --git a/examples/ldrstrsmall.s b/examples/ldrstrsmall.s new file mode 100644 index 0000000000000000000000000000000000000000..02430447fc5b569aff9d6168cfd8c4812a7a8d79 --- /dev/null +++ b/examples/ldrstrsmall.s @@ -0,0 +1,5 @@ +MOV R0 15; +MOV R1 -65536; +STR R1 15 R0; +LDR R2 R1 0; +RET R2; \ No newline at end of file diff --git a/examples/mov.s b/examples/mov.s new file mode 100644 index 0000000000000000000000000000000000000000..5d547a4a0737a1c1f20e8b6caf39e183ab816d35 --- /dev/null +++ b/examples/mov.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 5; +RET R0; \ No newline at end of file diff --git a/examples/movlong.s b/examples/movlong.s new file mode 100644 index 0000000000000000000000000000000000000000..9017ec8da5fc3938d30accab0deee58bbac49438 --- /dev/null +++ b/examples/movlong.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0 R1 5; +RET R0; \ No newline at end of file diff --git a/examples/movshort.s b/examples/movshort.s new file mode 100644 index 0000000000000000000000000000000000000000..b142235cae0b0a336b0560154fd4e83d37870a43 --- /dev/null +++ b/examples/movshort.s @@ -0,0 +1,3 @@ +MOV R0 1; +MOV R0; +RET R0; \ No newline at end of file diff --git a/examples/mul.s b/examples/mul.s new file mode 100644 index 0000000000000000000000000000000000000000..99dc9cf9d6cf1cb3efda4aff26e9d5e0569986f8 --- /dev/null +++ b/examples/mul.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R2 4; +MUL R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/mullong.s b/examples/mullong.s new file mode 100644 index 0000000000000000000000000000000000000000..35d8339f70b4286f8b2d6857a84deb0913836f66 --- /dev/null +++ b/examples/mullong.s @@ -0,0 +1,5 @@ +MOV R1 3; +MOV R2 4; +MOV R3 5; +MUL R0 R1 R2 R3; +RET R0; \ No newline at end of file diff --git a/examples/mulshort.s b/examples/mulshort.s new file mode 100644 index 0000000000000000000000000000000000000000..485fb692c050f6c07f75ed5ee732c008193f757a --- /dev/null +++ b/examples/mulshort.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R2 4; +MUL R0 R1; +RET R0; \ No newline at end of file diff --git a/examples/noret.s b/examples/noret.s new file mode 100644 index 0000000000000000000000000000000000000000..9962e76cc02fe86ffe879bcc454ad0a61b8eab34 --- /dev/null +++ b/examples/noret.s @@ -0,0 +1,3 @@ +MOV R1 3; +MOV R2 4; +ADD R0 R1 R2; \ No newline at end of file diff --git a/examples/oneline.s b/examples/oneline.s new file mode 100644 index 0000000000000000000000000000000000000000..6e67d3cfe8f750248dbc88f01f70317711a6dc3d --- /dev/null +++ b/examples/oneline.s @@ -0,0 +1 @@ +RET R0; \ No newline at end of file diff --git a/examples/register30.s b/examples/register30.s new file mode 100644 index 0000000000000000000000000000000000000000..580e1a8a474ccab97bf90c52ff59bc26bbbe1109 --- /dev/null +++ b/examples/register30.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R31 4; +ADD R0 R1 R31; +RET R0; \ No newline at end of file diff --git a/examples/retlong.s b/examples/retlong.s new file mode 100644 index 0000000000000000000000000000000000000000..4ebd2bb17be538d40e37588bd74c48a20aa367db --- /dev/null +++ b/examples/retlong.s @@ -0,0 +1,4 @@ +MOV R1 3; +MOV R2 4; +ADD R0 R1 R2; +RET R0 R1 R2; \ No newline at end of file diff --git a/examples/strlong.s b/examples/strlong.s new file mode 100644 index 0000000000000000000000000000000000000000..975f6fd3d1588db51cd1544e9a9d1a1d139ba35c --- /dev/null +++ b/examples/strlong.s @@ -0,0 +1,6 @@ +MOV R0 13; +MOV R1 60; +STR R1 15 R0 R0; +MOV R2 37; +LDR R3 R2 38; +RET R3; \ No newline at end of file diff --git a/examples/strshort.s b/examples/strshort.s new file mode 100644 index 0000000000000000000000000000000000000000..1c4ef2ea330aa0c42815c577d2ef494c45b9d281 --- /dev/null +++ b/examples/strshort.s @@ -0,0 +1,6 @@ +MOV R0 13; +MOV R1 60; +STR R1 15; +MOV R2 37; +LDR R3 R2 38; +RET R3; \ No newline at end of file diff --git a/examples/sub.s b/examples/sub.s new file mode 100644 index 0000000000000000000000000000000000000000..d7d9510b244903cdb1f308614f9a469a082af4cd --- /dev/null +++ b/examples/sub.s @@ -0,0 +1,4 @@ +MOV R1 4; +MOV R2 7; +SUB R0 R1 R2; +RET R0; \ No newline at end of file diff --git a/examples/sublong.s b/examples/sublong.s new file mode 100644 index 0000000000000000000000000000000000000000..1cdf8998d8370d6bccb3c4da95dbfc715fcc5735 --- /dev/null +++ b/examples/sublong.s @@ -0,0 +1,5 @@ +MOV R1 4; +MOV R2 7; +MOV R3 1; +SUB R0 R1 R2 R3; +RET R0; \ No newline at end of file diff --git a/examples/subshort.s b/examples/subshort.s new file mode 100644 index 0000000000000000000000000000000000000000..6c6e752fa03f28a1813d6650e676c899d87b1052 --- /dev/null +++ b/examples/subshort.s @@ -0,0 +1,4 @@ +MOV R1 4; +MOV R2 7; +SUB R0 R1; +RET R0; \ No newline at end of file diff --git a/mutants/mutant-1/swen90006/machine/Machine.java b/mutants/mutant-1/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..1601984d0b00777807736fc8745e002576931fd4 100644 --- a/mutants/mutant-1/swen90006/machine/Machine.java +++ b/mutants/mutant-1/swen90006/machine/Machine.java @@ -73,7 +73,7 @@ public class Machine private void do_div(int dest, int src1, int src2) { - if (regs[src2] == 0){ + if (false){ /* no op */ }else{ regs[dest] = regs[src1] / regs[src2]; diff --git a/mutants/mutant-2/swen90006/machine/Machine.java b/mutants/mutant-2/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..ba00f5e1cdf39dd40af2ea0d943cc2b1f7a02c91 100644 --- a/mutants/mutant-2/swen90006/machine/Machine.java +++ b/mutants/mutant-2/swen90006/machine/Machine.java @@ -148,7 +148,7 @@ public class Machine private void validate_offset(int offset) throws InvalidInstructionException { - if (offset < -MAX_ADDR || offset > MAX_ADDR) { + if (offset <= -MAX_ADDR || offset > MAX_ADDR) { throw new InvalidInstructionException(); } } diff --git a/mutants/mutant-3/swen90006/machine/Machine.java b/mutants/mutant-3/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..a56907ab061d2c2cdfa9b43385b06b0bcd136701 100644 --- a/mutants/mutant-3/swen90006/machine/Machine.java +++ b/mutants/mutant-3/swen90006/machine/Machine.java @@ -148,7 +148,7 @@ public class Machine private void validate_offset(int offset) throws InvalidInstructionException { - if (offset < -MAX_ADDR || offset > MAX_ADDR) { + if (offset < -MAX_ADDR || offset >= MAX_ADDR) { throw new InvalidInstructionException(); } } diff --git a/mutants/mutant-4/swen90006/machine/Machine.java b/mutants/mutant-4/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..eb7249fbb435213fb71a654147ec88aca585d522 100644 --- a/mutants/mutant-4/swen90006/machine/Machine.java +++ b/mutants/mutant-4/swen90006/machine/Machine.java @@ -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(); } } diff --git a/mutants/mutant-5/swen90006/machine/Machine.java b/mutants/mutant-5/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..ce9915bbfc259297f0a52e98b3500ed7527763e8 100644 --- a/mutants/mutant-5/swen90006/machine/Machine.java +++ b/mutants/mutant-5/swen90006/machine/Machine.java @@ -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(); } } diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 61ce1ca647f325fbf452047408c1e22d9befcb99..9335587f00aba0740fa42358ceaf872b974df726 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -24,51 +24,435 @@ public class BoundaryTests { } - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() + // lines = 0 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void zeroLines() { - //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); + final List<String> lines = readInstructions("examples/empty.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // lines = 1 + @Test public void oneLine() + { + final List<String> lines = readInstructions("examples/oneline.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 0); + } + + // command not a subset of ["ADD" .. "JZ] + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void invalidCommand() + { + final List<String> lines = readInstructions("examples/invalidcommand.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // ADD words = 3, Ra in R, program contains RET + @Test public void add() + { + final List<String> lines = readInstructions("examples/add.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 7); + } + + // ADD words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void addShort() + { + final List<String> lines = readInstructions("examples/addshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // ADD words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void addLong() + { + final List<String> lines = readInstructions("examples/addlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // Program does not contain RET + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void noret() + { + final List<String> lines = readInstructions("examples/noret.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // SUB words = 3 + @Test public void sub() + { + final List<String> lines = readInstructions("examples/sub.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, -3); + } + + // SUB words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void subShort() + { + final List<String> lines = readInstructions("examples/subshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // SUB words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void subLong() + { + final List<String> lines = readInstructions("examples/sublong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MUL words = 3 + @Test public void mul() + { + final List<String> lines = readInstructions("examples/mul.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 12); + } + + // MUL words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void mulShort() + { + final List<String> lines = readInstructions("examples/mulshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MUL words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void mulLong() + { + final List<String> lines = readInstructions("examples/mullong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // DIV words = 3, Rc != 0 + @Test public void div() + { + final List<String> lines = readInstructions("examples/div.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 2); + } + + // DIV words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void divShort() + { + final List<String> lines = readInstructions("examples/divshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // DIV words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void divLong() + { + final List<String> lines = readInstructions("examples/divlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // Rc = 0 (divide by zero) + @Test public void divzero() + { + final List<String> lines = readInstructions("examples/divzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 17); + } + + // MOV words = 2 + @Test public void mov() + { + final List<String> lines = readInstructions("examples/mov.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 5); + } + + // MOV words < 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void movShort() + { + final List<String> lines = readInstructions("examples/movshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MOV words > 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void movLong() + { + final List<String> lines = readInstructions("examples/movlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // register > 31 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void invalidRegister() + { + final List<String> lines = readInstructions("examples/invalidregister.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // register = 31 + @Test public void register30() + { + final List<String> lines = readInstructions("examples/register30.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 7); + } + + // val < INT_MIN + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void intSmall() + { + final List<String> lines = readInstructions("examples/intsmall.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // val > INT_MAX + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void intLarge() + { + final List<String> lines = readInstructions("examples/intlarge.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // val = INT_MIN + @Test public void intMin() + { + final List<String> lines = readInstructions("examples/intmin.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, -65535); + } + + // val = INT_MAX + @Test public void intMax() + { + final List<String> lines = readInstructions("examples/intmax.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 65535); + } + + // LDR words = 3, STR words = 3 + @Test public void ldrStr() + { + final List<String> lines = readInstructions("examples/ldrstr.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 13); + } + + // LDR words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrShort() + { + final List<String> lines = readInstructions("examples/ldrshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrLong() + { + final List<String> lines = readInstructions("examples/ldrlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR b + v > MAX_ADDR + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrBig() + { + final List<String> lines = readInstructions("examples/ldrstrbig.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR b + v < -MAX_ADDR + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrSmall() + { + final List<String> lines = readInstructions("examples/ldrstrsmall.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR b + v = MAX_ADDR + @Test public void ldrMax() + { + final List<String> lines = readInstructions("examples/ldrstrmax.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 0); + } + + @Test public void ldrMin() + { + final List<String> lines = readInstructions("examples/ldrstrmin.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 0); + } + + // STR words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void strShort() + { + final List<String> lines = readInstructions("examples/strshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // STR words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void strLong() + { + final List<String> lines = readInstructions("examples/strlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP words = 1, 0 < pc + val < program length + @Test public void jmp() + { + final List<String> lines = readInstructions("examples/jmp.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 5); + } + + // JMP words < 1 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jmpShort() + { + final List<String> lines = readInstructions("examples/jmpshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP words > 1 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jmpLong() + { + final List<String> lines = readInstructions("examples/jmplong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP pc + val > program length + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jmpFwdJump() + { + final List<String> lines = readInstructions("examples/jmpfwdjump.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP pc + val < 0 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jmpBackJump() + { + final List<String> lines = readInstructions("examples/jmpbackjump.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JZ words = 2, Ra == 0, pc + val = program length - 1 + @Test public void jz() + { + final List<String> lines = readInstructions("examples/jz.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 0); + } + + // JZ words = 2, Ra != 0 + @Test public void jznotzero() + { + final List<String> lines = readInstructions("examples/jznotzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 5); } - @Test public void anotherTest() + // jZ words < 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jzShort() { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); + final List<String> lines = readInstructions("examples/jzshort.s"); + Machine m = new Machine(); + m.execute(lines); + } - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); + // JZ words > 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jzLong() + { + final List<String> lines = readInstructions("examples/jzlong.s"); + Machine m = new Machine(); + m.execute(lines); } - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() + // JZ Ra==0, pc + val = program length + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jzFwd() { - final List<String> lines = readInstructions("examples/array.s"); + final List<String> lines = readInstructions("examples/jzfwd.s"); Machine m = new Machine(); - assertEquals(m.execute(lines), 45); + m.execute(lines); } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable + + // jZ Ra==0, pc + val = -1 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jzBack() { - throw new java.io.IOException(); + final List<String> lines = readInstructions("examples/jzback.s"); + Machine m = new Machine(); + m.execute(lines); } - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() + // JZ Ra==0, pc + val = 0 + public void jzZero() { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); + final List<String> lines = readInstructions("examples/jzzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 15); + } + + // Check that blank lines are ignored + @Test public void blankLine() + { + final List<String> lines = readInstructions("examples/blankline.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 7); } //Read in a file containing a program and convert into a list of diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 5494b44f4615351a610fc7b0b649d30b4b2d0a40..7f1c664397e6c726388c99bee1561755219d3faa 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -24,55 +24,400 @@ public class PartitioningTests { } - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() +// lines = 0 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void zeroLines() { - //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); + final List<String> lines = readInstructions("examples/empty.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // lines = 1 + @Test public void oneLine() + { + final List<String> lines = readInstructions("examples/oneline.s"); + Machine m = new Machine(); + m.execute(lines); + } + // command not a subset of ["ADD" .. "JZ] + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void invalidCommand() + { + final List<String> lines = readInstructions("examples/invalidcommand.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // ADD words = 3, Ra in R, program contains RET + @Test public void add() + { + final List<String> lines = readInstructions("examples/add.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 7); + } + + // ADD words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void addShort() + { + final List<String> lines = readInstructions("examples/addshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // ADD words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void addLong() + { + final List<String> lines = readInstructions("examples/addlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // Program does not contain RET + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void noret() + { + final List<String> lines = readInstructions("examples/noret.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // SUB words = 3 + @Test public void sub() + { + final List<String> lines = readInstructions("examples/sub.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, -3); + } + + // SUB words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void subShort() + { + final List<String> lines = readInstructions("examples/subshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // SUB words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void subLong() + { + final List<String> lines = readInstructions("examples/sublong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MUL words = 3 + @Test public void mul() + { + final List<String> lines = readInstructions("examples/mul.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 12); + } + + // MUL words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void mulShort() + { + final List<String> lines = readInstructions("examples/mulshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MUL words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void mulLong() + { + final List<String> lines = readInstructions("examples/mullong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // DIV words = 3, Rc != 0 + @Test public void div() + { + final List<String> lines = readInstructions("examples/div.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 2); + } + + // DIV words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void divShort() + { + final List<String> lines = readInstructions("examples/divshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // DIV words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void divLong() + { + final List<String> lines = readInstructions("examples/divlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // Rc = 0 (divide by zero) + @Test public void divzero() + { + final List<String> lines = readInstructions("examples/divzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 17); + } + + // MOV words = 2 + @Test public void mov() + { + final List<String> lines = readInstructions("examples/mov.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 5); + } + + // MOV words < 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void movShort() + { + final List<String> lines = readInstructions("examples/movshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // MOV words > 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void movLong() + { + final List<String> lines = readInstructions("examples/movlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // register > 31 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void invalidRegister() + { + final List<String> lines = readInstructions("examples/invalidregister.s"); + Machine m = new Machine(); + m.execute(lines); } - @Test public void anotherTest() + // ra not a register (is an int) + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void invalidRegister2() { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); + final List<String> lines = readInstructions("examples/invalidregister2.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // val < INT_MIN + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void intSmall() + { + final List<String> lines = readInstructions("examples/intsmall.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // val > INT_MAX + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void intLarge() + { + final List<String> lines = readInstructions("examples/intlarge.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR words = 3, STR words = 3 + @Test public void ldrStr() + { + final List<String> lines = readInstructions("examples/ldrstr.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 13); + } + + // LDR words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrShort() + { + final List<String> lines = readInstructions("examples/ldrshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrLong() + { + final List<String> lines = readInstructions("examples/ldrlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR b + v > MAX_ADDR + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrBig() + { + final List<String> lines = readInstructions("examples/ldrstrbig.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // LDR b + v < -MAX_ADDR + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void ldrSmall() + { + final List<String> lines = readInstructions("examples/ldrstrsmall.s"); + Machine m = new Machine(); + m.execute(lines); + } - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); + // STR words < 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void strShort() + { + final List<String> lines = readInstructions("examples/strshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // STR words > 3 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void strLong() + { + final List<String> lines = readInstructions("examples/strlong.s"); + Machine m = new Machine(); + m.execute(lines); } - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() + // JMP words = 1, 0 < pc + val < program length + @Test public void jmp() { - final List<String> lines = readInstructions("examples/array.s"); + final List<String> lines = readInstructions("examples/jmp.s"); Machine m = new Machine(); - assertEquals(m.execute(lines), 45); + int result = m.execute(lines); + Assert.assertEquals(result, 5); } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable + + // JMP words < 1 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jmpShort() { - throw new java.io.IOException(); + final List<String> lines = readInstructions("examples/jmpshort.s"); + Machine m = new Machine(); + m.execute(lines); } - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() + // JMP words > 1 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jmpLong() { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); + final List<String> lines = readInstructions("examples/jmplong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP pc + val > program length + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jmpFwdJump() + { + final List<String> lines = readInstructions("examples/jmpfwdjump.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JMP pc + val < 0 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jmpBackJump() + { + final List<String> lines = readInstructions("examples/jmpbackjump.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JZ words = 2, Ra == 0, 0 < pc + val < program length + @Test public void jz() + { + final List<String> lines = readInstructions("examples/jz.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 0); + } + + // JZ words = 2, Ra != 0 + @Test public void jznotzero() + { + final List<String> lines = readInstructions("examples/jznotzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 5); + } + + // jZ words < 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jzShort() + { + final List<String> lines = readInstructions("examples/jzshort.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JZ words > 2 + @Test(expected = swen90006.machine.InvalidInstructionException.class) + public void jzLong() + { + final List<String> lines = readInstructions("examples/jzlong.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JZ Ra==0, pc + val > program length + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jzFwd() + { + final List<String> lines = readInstructions("examples/jzfwd.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // jZ Ra==0, pc + val < 0 + @Test(expected = swen90006.machine.NoReturnValueException.class) + public void jzBack() + { + final List<String> lines = readInstructions("examples/jzback.s"); + Machine m = new Machine(); + m.execute(lines); + } + + // JZ Ra==0, pc + val = 0 + public void jzZero() + { + final List<String> lines = readInstructions("examples/jzzero.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 15); + } + + // Check that blank lines are ignored + @Test public void blankLine() + { + final List<String> lines = readInstructions("examples/blankline.s"); + Machine m = new Machine(); + int result = m.execute(lines); + Assert.assertEquals(result, 7); } - //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");