diff --git a/Project-01/uap25-pro01-tram/src/de/unitrier/st/uap/w25/tram/AbstractMachineTests.java b/Project-01/uap25-pro01-tram/src/de/unitrier/st/uap/w25/tram/AbstractMachineTests.java index 4650aaa..4f58fe5 100644 --- a/Project-01/uap25-pro01-tram/src/de/unitrier/st/uap/w25/tram/AbstractMachineTests.java +++ b/Project-01/uap25-pro01-tram/src/de/unitrier/st/uap/w25/tram/AbstractMachineTests.java @@ -14,6 +14,8 @@ public class AbstractMachineTests { assertTrue(tram.isHalted(), "Machine should halt."); int y = tram.results().get(1); assertEquals(28, y, "Expected y = 6*3 + 5*2 = 28."); + int x = tram.results().get(0); + assertEquals(6, x, "See test output."); } @Test @@ -24,8 +26,9 @@ public class AbstractMachineTests { assertTrue(tram.isHalted(), "Machine should halt."); var results = tram.results(); - assertEquals(200, results.get(results.size() - 2), "Expected value 200 since x!=0."); - assertEquals(3, results.getLast(), "Expected final constant 3 on stack."); + assertEquals(200, results.get(1), "Expected value 200 since x!=0."); + assertEquals(3, results.get(2), "Expected final constant 3 on stack."); + assertEquals(10, results.get(0), "See test output."); } @Test @@ -40,7 +43,7 @@ public class AbstractMachineTests { } @Test - void testSquareFunction() { + void testSquare() { Instruction[] code = Assembler.readTRAMCode("tramcode/square.tram"); AbstractMachine tram = new AbstractMachine(code, new Integer[]{}); // empty stack tram.execute(); @@ -62,7 +65,7 @@ public class AbstractMachineTests { } @Test - void testWrapperSquare() { + void testWrappedSquare() { Instruction[] code = Assembler.readTRAMCode("tramcode/wrapper.tram"); AbstractMachine tram = new AbstractMachine(code, new Integer[]{}); // empty stack tram.execute(); @@ -116,6 +119,28 @@ public class AbstractMachineTests { assertEquals(5, result, "Expected 37 mod 16 = 5."); } + @Test + void testMODx100y7() { + Instruction[] code = Assembler.readTRAMCode("tramcode/mod.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{100, 7}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(2, result, "Expected 100 mod 7 = 2."); + } + + @Test + void testMODx1y10() { + Instruction[] code = Assembler.readTRAMCode("tramcode/mod.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{1, 10}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(1, result, "Expected 1 mod 10 = 1."); + } + @Test void testGGTx17y5() { Instruction[] code = Assembler.readTRAMCode("tramcode/ggt.tram"); @@ -225,4 +250,48 @@ public class AbstractMachineTests { int result = tram.result(); assertEquals(1, result, "Expected ggt(37,16) = 1."); } + + @Test + void testGGTx100y50() { + Instruction[] code = Assembler.readTRAMCode("tramcode/ggt.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{100, 50}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(50, result, "Expected ggt(100,50) = 50."); + } + + @Test + void testGGTx13y13() { + Instruction[] code = Assembler.readTRAMCode("tramcode/ggt.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{13, 13}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(13, result, "Expected ggt(13,13) = 13."); + } + + @Test + void testGGTx84y36() { + Instruction[] code = Assembler.readTRAMCode("tramcode/ggt.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{84, 36}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(12, result, "Expected ggt(84,36) = 12."); + } + + @Test + void testGGTx1y100() { + Instruction[] code = Assembler.readTRAMCode("tramcode/ggt.tram"); + AbstractMachine tram = new AbstractMachine(code, new Integer[]{1, 100}); + tram.execute(); + + assertTrue(tram.isHalted(), "Machine should halt."); + int result = tram.result(); + assertEquals(1, result, "Expected ggt(1,100) = 1."); + } }