Zomis / Brainduck

Brainfuck Interpreter in Java/Groovy, with a Groovy DSL
40 stars 1 forks source link

Test cases for loops #54

Open Zomis opened 7 years ago

Zomis commented 7 years ago

It would be nice to be able to test that loops do what they are supposed to do

As a simple example consider the code:

$ nextLoop 'testable-loop'
[+++>++>-]

and the DSL:

$ {
     test 'testable-loop' memory '3 x4 5 2 0 1' expect '3 7 7 1 0 x0'
     test 'testable-loop' memory '3 x4 5 2 0 2 0 1' expect '3 7 7 1 0 4 2 x0'
}

x indicates the memory cell pointer.

Both the above tests should then pass.

Could be useful to test some loops in http://codereview.stackexchange.com/q/57382/31562 , for example to perform one fizz-buzz loop, process one Fizz, etc.

This has potential to be extended quite a bit, for example with expect *, asserting that pointer never leaves the allocated memory, and probably more.

Named memory cells might be useful for parts of this ( #14 )