MCPcopy Index your code
hub / github.com/btcsuite/btcd / TestScriptNumInt32

Function TestScriptNumInt32

txscript/scriptnum_test.go:216–273  ·  view source on GitHub ↗

TestScriptNumInt32 ensures that the Int32 function on script number behaves as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

214// TestScriptNumInt32 ensures that the Int32 function on script number behaves
215// as expected.
216func TestScriptNumInt32(t *testing.T) {
217 t.Parallel()
218
219 tests := []struct {
220 in scriptNum
221 want int32
222 }{
223 // Values inside the valid int32 range are just the values
224 // themselves cast to an int32.
225 {0, 0},
226 {1, 1},
227 {-1, -1},
228 {127, 127},
229 {-127, -127},
230 {128, 128},
231 {-128, -128},
232 {129, 129},
233 {-129, -129},
234 {256, 256},
235 {-256, -256},
236 {32767, 32767},
237 {-32767, -32767},
238 {32768, 32768},
239 {-32768, -32768},
240 {65535, 65535},
241 {-65535, -65535},
242 {524288, 524288},
243 {-524288, -524288},
244 {7340032, 7340032},
245 {-7340032, -7340032},
246 {8388608, 8388608},
247 {-8388608, -8388608},
248 {2147483647, 2147483647},
249 {-2147483647, -2147483647},
250 {-2147483648, -2147483648},
251
252 // Values outside of the valid int32 range are limited to int32.
253 {2147483648, 2147483647},
254 {-2147483649, -2147483648},
255 {1152921504606846975, 2147483647},
256 {-1152921504606846975, -2147483648},
257 {2305843009213693951, 2147483647},
258 {-2305843009213693951, -2147483648},
259 {4611686018427387903, 2147483647},
260 {-4611686018427387903, -2147483648},
261 {9223372036854775807, 2147483647},
262 {-9223372036854775808, -2147483648},
263 }
264
265 for _, test := range tests {
266 got := test.in.Int32()
267 if got != test.want {
268 t.Errorf("Int32: did not get expected value for %d - "+
269 "got %d, want %d", test.in, got, test.want)
270 continue
271 }
272 }
273}

Callers

nothing calls this directly

Calls 1

Int32Method · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…