From c0567e2492ece720f87d1b5f74abce86fad815dc Mon Sep 17 00:00:00 2001 From: Georgi Stefanov Date: Thu, 29 Nov 2018 15:03:08 +0200 Subject: Add brainfuck interpreter (#65) Not sure if it builds correctly. You have to have go compiler. --- .../81319/bfinterpreter/bf/interpreter_test.go | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 homework/81319/bfinterpreter/bf/interpreter_test.go (limited to 'homework/81319/bfinterpreter/bf/interpreter_test.go') 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) + +} -- cgit v1.3.1-26-gb76a