-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
57 lines (44 loc) · 987 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bytes"
"os"
"testing"
)
func eval(s string) string {
bf := newBf(bytes.NewBufferString(s))
bf.Eval()
return bf.IntString()
}
func TestIntData(t *testing.T) {
type TestCase struct {
Input string
Want string
}
for _, tc := range []TestCase{
{"++.+>[-.]", "30"},
{"+", "1"},
{"j+<++", "021"},
{"[ empty [loop] inner ] >> ++", "002"},
{"[ [] ++] >+", "01"},
{"+++[>>+<<- ]+>++", "123"},
{"++++++++ >++++ >++ >+++ >+++ >+ >+++", "8423313"},
{` ++ > +++++ [ < + > - ] ++++ ++++ [ < +++ +++ > -] < .`, "550"},
} {
got := eval(tc.Input)
if tc.Want != got {
t.Errorf("Fail on input: %s\nWant: '%s'\nGot : '%s'", tc.Input, tc.Want, got)
}
}
}
func TestHelloWorld(t *testing.T) {
f, _ := os.Open("hello_world.bf")
bf := newBf(f)
bf.Eval()
got := bf.DataCells[:7]
want := []int{0, 0, 72, 100, 87, 33, 10}
for i, v := range got {
if want[i] != v {
t.Errorf("want: '%v', got: '%v'", want, got)
}
}
}