summaryrefslogtreecommitdiff
path: root/go/forth/forth_test.go
blob: 0eff3c66958e1baf4f8e8ab89227e1bec911ea18 (plain)
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
package forth

// API:
// func Forth([]string) ([]int, error)
//

import (
	"reflect"
	"testing"
)

func TestForth(t *testing.T) {
	for _, tg := range testGroups {
		for _, tc := range tg.tests {
			if v, err := Forth(tc.input); err == nil {
				var _ error = err
				if tc.expected == nil {
					t.Fatalf("FAIL: %s | %s\n\tForth(%#v) expected an error, got %v",
						tg.group, tc.description, tc.input, v)
				} else if !reflect.DeepEqual(v, tc.expected) {
					t.Fatalf("FAIL: %s | %s\n\tForth(%#v) expected %v, got %v",
						tg.group, tc.description, tc.input, tc.expected, v)
				}
			} else if tc.expected != nil {
				t.Fatalf("FAIL: %s | %s\n\tForth(%#v) expected %v, got an error: %q",
					tg.group, tc.description, tc.input, tc.expected, err)
			}
			t.Logf("PASS: %s | %s", tg.group, tc.description)
		}
	}
}

func BenchmarkForth(b *testing.B) {
	for i := 0; i < b.N; i++ {
		for _, tg := range testGroups {
			for _, tc := range tg.tests {
				Forth(tc.input)
			}
		}
	}
}