11 func TestInt64(t *testing.T) {
13 f func(a, b int64) (int64, bool)
17 {AddInt64, 2, 3, 5, true},
18 {AddInt64, 2, -3, -1, true},
19 {AddInt64, -2, -3, -5, true},
20 {AddInt64, math.MaxInt64, 1, 0, false},
21 {AddInt64, math.MinInt64, math.MinInt64, 0, false},
22 {AddInt64, math.MinInt64, -1, 0, false},
23 {SubInt64, 3, 2, 1, true},
24 {SubInt64, 2, 3, -1, true},
25 {SubInt64, -2, -3, 1, true},
26 {SubInt64, math.MinInt64, 1, 0, false},
27 {SubInt64, -2, math.MaxInt64, 0, false},
28 {MulInt64, 2, 3, 6, true},
29 {MulInt64, -2, -3, 6, true},
30 {MulInt64, -2, 3, -6, true},
31 {MulInt64, math.MaxInt64, -1, math.MinInt64 + 1, true},
32 {MulInt64, math.MinInt64, 2, 0, false},
33 {MulInt64, math.MaxInt64, 2, 0, false},
34 {MulInt64, 2, math.MinInt64, 0, false},
35 {MulInt64, -2, math.MinInt64, 0, false},
36 {DivInt64, 2, 2, 1, true},
37 {DivInt64, -2, -2, 1, true},
38 {DivInt64, -2, 2, -1, true},
39 {DivInt64, 1, 0, 0, false},
40 {DivInt64, math.MinInt64, -1, 0, false},
41 {ModInt64, 3, 2, 1, true},
42 {ModInt64, -3, -2, -1, true},
43 {ModInt64, -3, 2, -1, true},
44 {ModInt64, 1, 0, 0, false},
45 {ModInt64, math.MinInt64, -1, 0, false},
46 {LshiftInt64, 1, 2, 4, true},
47 {LshiftInt64, -1, 2, -4, true},
48 {LshiftInt64, 1, 64, 0, false},
49 {LshiftInt64, 2, 63, 0, false},
52 for _, c := range cases {
53 got, gotOk := c.f(c.a, c.b)
56 t.Errorf("%s(%d, %d) = %d want %d", fname(c.f), c.a, c.b, got, c.want)
59 if gotOk != c.wantOk {
60 t.Errorf("%s(%d, %d) ok = %v want %v", fname(c.f), c.a, c.b, gotOk, c.wantOk)
64 negateCases := []struct {
71 {math.MinInt64, 0, false},
73 for _, c := range negateCases {
74 got, gotOk := NegateInt64(c.a)
77 t.Errorf("NegateInt64(%d) = %d want %d", c.a, got, c.want)
80 if gotOk != c.wantOk {
81 t.Errorf("NegateInt64(%d) ok = %v want %v", c.a, gotOk, c.wantOk)
86 func TestUint64(t *testing.T) {
88 f func(a, b uint64) (uint64, bool)
92 {AddUint64, 2, 3, 5, true},
93 {AddUint64, math.MaxUint64, 1, 0, false},
94 {SubUint64, 3, 2, 1, true},
95 {SubUint64, 2, 3, 0, false},
96 {MulUint64, 2, 3, 6, true},
97 {MulUint64, math.MaxUint64, 2, 0, false},
98 {DivUint64, 2, 2, 1, true},
99 {DivUint64, 1, 0, 0, false},
100 {ModUint64, 3, 2, 1, true},
101 {ModUint64, 1, 0, 0, false},
102 {LshiftUint64, 1, 2, 4, true},
103 {LshiftUint64, 1, 64, 0, false},
104 {LshiftUint64, 2, 63, 0, false},
107 for _, c := range cases {
108 got, gotOk := c.f(c.a, c.b)
111 t.Errorf("%s(%d, %d) = %d want %d", fname(c.f), c.a, c.b, got, c.want)
114 if gotOk != c.wantOk {
115 t.Errorf("%s(%d, %d) ok = %v want %v", fname(c.f), c.a, c.b, gotOk, c.wantOk)
120 func TestInt32(t *testing.T) {
122 f func(a, b int32) (int32, bool)
126 {AddInt32, 2, 3, 5, true},
127 {AddInt32, 2, -3, -1, true},
128 {AddInt32, -2, -3, -5, true},
129 {AddInt32, math.MaxInt32, 1, 0, false},
130 {AddInt32, math.MinInt32, math.MinInt32, 0, false},
131 {AddInt32, math.MinInt32, -1, 0, false},
132 {SubInt32, 3, 2, 1, true},
133 {SubInt32, 2, 3, -1, true},
134 {SubInt32, -2, -3, 1, true},
135 {SubInt32, math.MinInt32, 1, 0, false},
136 {SubInt32, -2, math.MaxInt32, 0, false},
137 {MulInt32, 2, 3, 6, true},
138 {MulInt32, -2, -3, 6, true},
139 {MulInt32, -2, 3, -6, true},
140 {MulInt32, math.MaxInt32, -1, math.MinInt32 + 1, true},
141 {MulInt32, math.MinInt32, 2, 0, false},
142 {MulInt32, math.MaxInt32, 2, 0, false},
143 {MulInt32, 2, math.MinInt32, 0, false},
144 {MulInt32, -2, math.MinInt32, 0, false},
145 {DivInt32, 2, 2, 1, true},
146 {DivInt32, -2, -2, 1, true},
147 {DivInt32, -2, 2, -1, true},
148 {DivInt32, 1, 0, 0, false},
149 {DivInt32, math.MinInt32, -1, 0, false},
150 {ModInt32, 3, 2, 1, true},
151 {ModInt32, -3, -2, -1, true},
152 {ModInt32, -3, 2, -1, true},
153 {ModInt32, 1, 0, 0, false},
154 {ModInt32, math.MinInt32, -1, 0, false},
155 {LshiftInt32, 1, 2, 4, true},
156 {LshiftInt32, -1, 2, -4, true},
157 {LshiftInt32, 1, 32, 0, false},
158 {LshiftInt32, 2, 31, 0, false},
161 for _, c := range cases {
162 got, gotOk := c.f(c.a, c.b)
165 t.Errorf("%s(%d, %d) = %d want %d", fname(c.f), c.a, c.b, got, c.want)
168 if gotOk != c.wantOk {
169 t.Errorf("%s(%d, %d) ok = %v want %v", fname(c.f), c.a, c.b, gotOk, c.wantOk)
173 negateCases := []struct {
180 {math.MinInt32, 0, false},
182 for _, c := range negateCases {
183 got, gotOk := NegateInt32(c.a)
186 t.Errorf("NegateInt32(%d) = %d want %d", c.a, got, c.want)
189 if gotOk != c.wantOk {
190 t.Errorf("NegateInt32(%d) ok = %v want %v", c.a, gotOk, c.wantOk)
195 func TestUint32(t *testing.T) {
197 f func(a, b uint32) (uint32, bool)
201 {AddUint32, 2, 3, 5, true},
202 {AddUint32, math.MaxUint32, 1, 0, false},
203 {SubUint32, 3, 2, 1, true},
204 {SubUint32, 2, 3, 0, false},
205 {MulUint32, 2, 3, 6, true},
206 {MulUint32, math.MaxUint32, 2, 0, false},
207 {DivUint32, 2, 2, 1, true},
208 {DivUint32, 1, 0, 0, false},
209 {ModUint32, 3, 2, 1, true},
210 {ModUint32, 1, 0, 0, false},
211 {LshiftUint32, 1, 2, 4, true},
212 {LshiftUint32, 1, 32, 0, false},
213 {LshiftUint32, 2, 31, 0, false},
216 for _, c := range cases {
217 got, gotOk := c.f(c.a, c.b)
220 t.Errorf("%s(%d, %d) = %d want %d", fname(c.f), c.a, c.b, got, c.want)
223 if gotOk != c.wantOk {
224 t.Errorf("%s(%d, %d) ok = %v want %v", fname(c.f), c.a, c.b, gotOk, c.wantOk)
229 func fname(f interface{}) string {
230 name := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
231 return name[strings.IndexRune(name, '.')+1:]