simon987 / Much-Assembly-Required

Assembly programming game

Home Page:https://muchassemblyrequired.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding tests is really hard

kevinramharak opened this issue · comments

Hey Simon,

I was trying to add tests for each instruction because i am not confident they all work 100% correctly, but it is really hard to add tests for some instructions. For example the CallInstruction expects a CPU instance and the CPU instance either uses the GameServer singleton (which does not exist in tests) or you can give it a fake config, but then you need to give it a Cubot instance.

The more complicated the instruction becomes the hard it is to test. I know you have some refactoring in mind. Any ideas on how to make testing easier to implement?

 Any ideas on how to make testing easier to implement?

It's definitely planned to add Fakes for Cubot & CPU etc. Even better would be to abstract all the Assembler/CPU code to allow for different ISAs. I'll keep you updated on my progress

I added some helper functions, let me know what you think.

Example:

public class CallInstructionTest {
@Test
public void callSimple1() {
String code = "" +
"my_routine: \n" +
" MOV X, 0x1234 \n" +
" RET \n" +
".text \n" +
"CALL my_routine \n" +
"MOV Y, 0x4567 \n" +
"brk \n";
TestExecutionResult res = TestHelper.executeCode(code);
assertEquals(0x1234, res.regValue("X"));
assertEquals(0x4567, res.regValue("Y"));
}
}

That seems way easier. Expressing the assembly in java is hard. This would make it trivial