Skip to content

Commit d9e2e28

Browse files
committed
Fixed test cases for St
1 parent 8563c63 commit d9e2e28

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/test/java/instruction/StTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ void setup() {
3030
void testStoreOperation() {
3131

3232
// Setup source and destination registers
33-
int op1 = Registry.nameToIdx(Registry.REG_R1);
34-
int op2 = Registry.nameToIdx(Registry.REG_RES);
35-
int operand = (op1 << 4) | op2;
33+
int operand = Registry.nameToIdx(Registry.REG_RES);
3634
int registerValue = 35; // The value stored in the source register
3735
int memoryAddress = 8; // The destination address in memory where the value should be stored
3836
int nextMemoryLocation = 1; // The next memory location according to the program counter
@@ -41,14 +39,13 @@ void testStoreOperation() {
4139
// destination address
4240
when(mockPC.next()).thenReturn(nextMemoryLocation);
4341

44-
// Simulate fetching the operand from memory
45-
when(mockMemory.getValueAt(nextMemoryLocation)).thenReturn(operand);
42+
// Simulate fetching the destination address from the memory
43+
when(mockMemory.getValueAt(nextMemoryLocation)).thenReturn(memoryAddress);
4644

4745
// Simulate fetching the value from the register specified by the operand
48-
when(mockRegistry.getValueAt(op1)).thenReturn(registerValue);
49-
when(mockRegistry.getValueAt(op2)).thenReturn(memoryAddress);
46+
when(mockRegistry.getValueAt(operand)).thenReturn(registerValue);
5047

51-
St stInstruction = new St(0);
48+
St stInstruction = new St(operand);
5249
stInstruction.execute(mockMemory, mockRegistry, mockPC, null);
5350

5451
// Verify memory's setValueAt method is called with the correct destination address and value
@@ -58,13 +55,15 @@ void testStoreOperation() {
5855

5956
@Test
6057
void testPrettyPrint() {
61-
St store = new St(0);
62-
int leftOp = Registry.nameToIdx(Registry.REG_R2);
63-
int rightOp = Registry.nameToIdx(Registry.REG_OP1);
64-
int operand = (leftOp << 4) | rightOp;
65-
when(mockMemory.getValueAt(1)).thenReturn(operand);
58+
// Setup source and destination registers
59+
int operand = Registry.nameToIdx(Registry.REG_RES);
60+
int memoryAddress = 8; // The destination address in memory where the value should be stored
61+
62+
when(mockMemory.getValueAt(1)).thenReturn(memoryAddress);
63+
64+
St store = new St(operand);
6665
assertEquals(
67-
InstructionFactory.INST_NAME_STO + " (R2 " + Instruction.RIGHT_ARROW_CHAR + " *OP1)",
66+
InstructionFactory.INST_NAME_STO + " (RES " + Instruction.RIGHT_ARROW_CHAR + " m[8])",
6867
store.prettyPrint(mockMemory, mockRegistry, 0));
6968
}
7069
}

todo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
[] Advanced hiding:
9999
[] Move the hidden status with the cells when moving/deleting values
100100
[] Let it reflect in file format, i.e. restore on reload
101-
[] Fix test for St (no longer StA)
101+
[x] Fix test for St (no longer StA)
102102
[x] Update example programs, after instruction changes (again...)
103103
[] Add config/view option to turn off auto scroll to active cell
104104
[] Think about: Should conditional jump use another dst register, e.g. R2? (Instead of RES)

0 commit comments

Comments
 (0)