Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81319 / bfinterpreter / bf / interpreter_test.go
diff options
context:
space:
mode:
Commitc0567e2492ece720f87d1b5f74abce86fad815dc (patch)
Author
 Georgi Stefanov <geosteffanov@gmail.com>
2018-11-29 15:03:08 +0200
Committer
 dtrendafilov <trendafilov.dn@gmail.com>
2018-11-29 15:03:08 +0200
Files48669f35b66d15eb29cb26d29ab6e03a8b4a142a /homework/81319/bfinterpreter/bf/interpreter_test.go
IPL-c0567e2492ece720f87d1b5f74abce86fad815dc.tar
IPL-c0567e2492ece720f87d1b5f74abce86fad815dc.tar.gz
IPL-c0567e2492ece720f87d1b5f74abce86fad815dc.zip
Parent99a9f9389a41a1df544ab51fc0170e48f10e34c8 (diff)
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.go58
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)
+
+}