MCPcopy Create free account
hub / github.com/chain/txvm / TestInt32

Function TestInt32

math/checked/checked_test.go:120–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestInt32(t *testing.T) {
121 cases := []struct {
122 f func(a, b int32) (int32, bool)
123 a, b, want int32
124 wantOk bool
125 }{
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},
159 }
160
161 for _, c := range cases {
162 got, gotOk := c.f(c.a, c.b)
163
164 if got != c.want {
165 t.Errorf("%s(%d, %d) = %d want %d", fname(c.f), c.a, c.b, got, c.want)
166 }
167
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)
170 }
171 }
172
173 negateCases := []struct {
174 a, want int32
175 wantOk bool
176 }{
177 {1, -1, true},

Callers

nothing calls this directly

Calls 2

fnameFunction · 0.85
NegateInt32Function · 0.85

Tested by

no test coverage detected