Skip to content

Commit 7549754

Browse files
committed
Oops, fixed test cases related to last commit :P
1 parent 4c75ecc commit 7549754

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/test/java/instruction/LdATest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,38 @@ void setup() {
2727

2828
@Test
2929
void testLoadFromAddressOperation() {
30-
int operand = Registry.nameToIdx(Registry.REG_R1); // Operand: register to load value into
30+
int op1 = Registry.nameToIdx(Registry.REG_R1);
31+
int op2 = Registry.nameToIdx(Registry.REG_RES);
32+
int operand = (op1 << 4) | op2;
3133
int value = 123; // The value to be loaded from memory
3234
int memoryAddress = 33; // The address in memory where value is stored
3335

3436
// Simulate the program counter pointing to the next memory address
3537
when(mockPC.next()).thenReturn(1);
3638

37-
// Simulate memory returning the memory address
38-
when(mockMemory.getValueAt(1)).thenReturn(memoryAddress);
39+
// Simulate fetching the operand from memory
40+
when(mockMemory.getValueAt(1)).thenReturn(operand);
3941

40-
// Simulate memory returning the value from the memory address
42+
// Simulate fetching the value from the register specified by the operand
43+
when(mockRegistry.getValueAt(op1)).thenReturn(memoryAddress);
4144
when(mockMemory.getValueAt(memoryAddress)).thenReturn(value);
4245

43-
LdA ldaInstruction = new LdA(operand);
46+
LdA ldaInstruction = new LdA(0);
4447
ldaInstruction.execute(mockMemory, mockRegistry, mockPC, null);
4548

4649
// Verify the registry's setRegister method is called with the correct value
47-
verify(mockRegistry).setValueAt(operand, value);
50+
verify(mockRegistry).setValueAt(op2, value);
4851
}
4952

5053
@Test
5154
void testPrettyPrint() {
52-
when(mockMemory.getValueAt(1)).thenReturn(81);
53-
54-
LdA load = new LdA(Registry.nameToIdx(Registry.REG_R1));
55+
LdA load = new LdA(0);
56+
int leftOp = Registry.nameToIdx(Registry.REG_R2);
57+
int rightOp = Registry.nameToIdx(Registry.REG_OP1);
58+
int operand = (leftOp << 4) | rightOp;
59+
when(mockMemory.getValueAt(1)).thenReturn(operand);
5560
assertEquals(
56-
InstructionFactory.INST_NAME_LDA + " (m[81] " + Instruction.RIGHT_ARROW_CHAR + " R1)",
61+
InstructionFactory.INST_NAME_LDA + " (*R2 " + Instruction.RIGHT_ARROW_CHAR + " OP1)",
5762
load.prettyPrint(mockMemory, mockRegistry, 0));
5863
}
5964
}

0 commit comments

Comments
 (0)