What is the good way to create "unit test" for vmtranslator?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

What is the good way to create "unit test" for vmtranslator?

bupjae
I took this class via Coursera few years ago, and I want to reiterate toolchain (assembler, vmtranslator, jackcompiler).
This time, I want to create unit test for each program.

Unit test for assembler was relatively easy.
For given .asm file, each line is exactly one way to translate. i.e, `@R6` is always translated to `0000000000000110`. So unit test of assembler is simple text comparator.

However, each command of VM has various way to translate to assembler.
For example, my first attempt to translate`push constant 0` was `@0 D=A @SP A=M M=D @SP M=M+1`, and later I changed to `@SP AM=M+1 A=A-1 M=0`. Net effect on memory of both code is same.

I want to write test code so that both implementation of `push constant 0` can be passed. However, I think it is very hard without writing CPUEmulator first, and it is too much for just unit test.

What would be good way to create unit test?