diff options
Add brainfuck interpreter (#65)
Not sure if it builds correctly.
You have to have go compiler.
1 files changed, 58 insertions, 0 deletions
| -rw-r--r-- | homework/81319/bfinterpreter/bf/interpreter_test.go | 58 |
diff --git a/homework/81319/bfinterpreter/bf/interpreter_test.go b/homework/81319/bfinterpreter/bf/interpreter_test.go new file mode 100644 index 0000000..a798669 --- /dev/null +++ b/homework/81319/bfinterpreter/bf/interpreter_test.go @@ -0,0 +1,58 @@ +package bf + +import ( + "bufio" + "io" + "os" + "testing" +) + +func TestInterpretInstruction(t *testing.T) { + var writer io.Writer + + writer = flushingWriter{ + w: bufio.NewWriter(os.Stdout), + } + + src := []instruction{ + { + idx: 0, + instructionType: incD, + }, + } + + for i := 0; i < 65; i++ { + src = append(src, instruction{ + idx: uint(i), + instructionType: incD, + }) + } + + src = append(src, instruction{ + idx: 65, + instructionType: outD, + }) + + intepreterState := state{ + src: src, + buffer: make([]byte, 1), + writer: writer, + } + + writer.Write([]byte("hello\n")) + + for i := 0; i < 66; i++ { + intepreterState.interpretInstruction() + } + + intepreterState.interpretInstruction() + +} + +func TestInterpreter(t *testing.T) { + input := "," + interpreter := NewInterpreter(input) + + Run(interpreter) + +} |
