-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
86 lines (69 loc) · 1.64 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import "testing"
func TestBasics(t *testing.T) {
tables := []struct {
expression string
result float64
}{
{"1+1", 2},
{"1+2", 3},
{"4+2+7", 13},
{"1-1", 0},
{"4-2", 2},
{"4-2-7", -5},
{"5+4-2", 7},
{"5-10+2", -3},
{"1*2", 2},
{"4*2", 8},
{"4*3*2", 24},
{"4/2", 2},
{"2/2", 1},
{"1/2", 0.5},
{"4/2/2/2", 0.5},
{"4*2/8", 1},
{"12/3*2", 8},
{"2+2*3+2", 10},
{"2*4+3*2-4/2", 12},
{"2^2", 4},
{"2^3", 8},
{"2*2^3", 16},
{"2^3*2", 16},
{"2^(3*2)", 64},
{"2^(2*3^2)", 262144},
}
for _, table := range tables {
total := basics(table.expression)
if total != table.result {
t.Errorf("TestBasics of (%s) was incorrect, got: %f, want: %f.", table.expression, total, table.result)
}
}
}
func TestVectorsBasics(t *testing.T) {
tables := []struct {
expression string
result []string
}{
{"(2,6)", []string{"2", "6"}},
{"(2,6)*2", []string{"4", "12"}},
{"(2,6)+(1,3)", []string{"3", "9"}},
{"(2,6)-(2,6)", []string{"0", "0"}},
{"(2,6)-(2,3)", []string{"0", "3"}},
{"(2,3)-(2,6)", []string{"0", "-3"}},
{"(2,6)*2+(2,6)", []string{"6", "18"}},
{"(2,6)*2+(1,3)*3", []string{"7", "21"}},
{"(2,6)*x", []string{"2*x", "6*x"}},
{"(2,y)-(x,6)", []string{"2-x", "y-6"}},
{"(2,y)+(x,6)", []string{"2+x", "y+6"}},
{"(2,y)*z+(x,6)*2", []string{"2*z+x*2", "y*z+12"}},
}
for _, table := range tables {
total := basicsVectors(table.expression)
count := len(total)
for i := 0; i < count; i++ {
if total[i] != table.result[i] {
t.Errorf("TestVectorsSplit of (%s) was incorrect, got: %s, want: %s.", table.expression, total, table.result)
break
}
}
}
}