diff options
Diffstat (limited to 'src/pkg/big/int_test.go')
-rwxr-xr-x | src/pkg/big/int_test.go | 453 |
1 files changed, 230 insertions, 223 deletions
diff --git a/src/pkg/big/int_test.go b/src/pkg/big/int_test.go index 269c814d4..fc981e1da 100755 --- a/src/pkg/big/int_test.go +++ b/src/pkg/big/int_test.go @@ -29,24 +29,36 @@ type argZZ struct { var sumZZ = []argZZ{ - argZZ{NewInt(0), NewInt(0), NewInt(0)}, - argZZ{NewInt(1), NewInt(1), NewInt(0)}, - argZZ{NewInt(1111111110), NewInt(123456789), NewInt(987654321)}, - argZZ{NewInt(-1), NewInt(-1), NewInt(0)}, - argZZ{NewInt(864197532), NewInt(-123456789), NewInt(987654321)}, - argZZ{NewInt(-1111111110), NewInt(-123456789), NewInt(-987654321)}, + {NewInt(0), NewInt(0), NewInt(0)}, + {NewInt(1), NewInt(1), NewInt(0)}, + {NewInt(1111111110), NewInt(123456789), NewInt(987654321)}, + {NewInt(-1), NewInt(-1), NewInt(0)}, + {NewInt(864197532), NewInt(-123456789), NewInt(987654321)}, + {NewInt(-1111111110), NewInt(-123456789), NewInt(-987654321)}, } var prodZZ = []argZZ{ - argZZ{NewInt(0), NewInt(0), NewInt(0)}, - argZZ{NewInt(0), NewInt(1), NewInt(0)}, - argZZ{NewInt(1), NewInt(1), NewInt(1)}, - argZZ{NewInt(-991 * 991), NewInt(991), NewInt(-991)}, + {NewInt(0), NewInt(0), NewInt(0)}, + {NewInt(0), NewInt(1), NewInt(0)}, + {NewInt(1), NewInt(1), NewInt(1)}, + {NewInt(-991 * 991), NewInt(991), NewInt(-991)}, // TODO(gri) add larger products } +func TestSignZ(t *testing.T) { + var zero Int + for _, a := range sumZZ { + s := a.z.Sign() + e := a.z.Cmp(&zero) + if s != e { + t.Errorf("got %d; want %d for z = %v", s, e, a.z) + } + } +} + + func TestSetZ(t *testing.T) { for _, a := range sumZZ { var z Int @@ -61,11 +73,28 @@ func TestSetZ(t *testing.T) { } +func TestAbsZ(t *testing.T) { + var zero Int + for _, a := range sumZZ { + var z Int + z.Abs(a.z) + var e Int + e.Set(a.z) + if e.Cmp(&zero) < 0 { + e.Sub(&zero, &e) + } + if z.Cmp(&e) != 0 { + t.Errorf("got z = %v; want %v", z, e) + } + } +} + + func testFunZZ(t *testing.T, msg string, f funZZ, a argZZ) { var z Int f(&z, a.x, a.y) if !isNormalized(&z) { - t.Errorf("msg: %v is not normalized", z, msg) + t.Errorf("%s%v is not normalized", z, msg) } if (&z).Cmp(a.z) != 0 { t.Errorf("%s%+v\n\tgot z = %v; want %v", msg, a, &z, a.z) @@ -157,28 +186,25 @@ func TestMul(t *testing.T) { } -type mulRangeZ struct { +var mulRangesZ = []struct { a, b int64 prod string -} - - -var mulRangesZ = []mulRangeZ{ +}{ // entirely positive ranges are covered by mulRangesN - mulRangeZ{-1, 1, "0"}, - mulRangeZ{-2, -1, "2"}, - mulRangeZ{-3, -2, "6"}, - mulRangeZ{-3, -1, "-6"}, - mulRangeZ{1, 3, "6"}, - mulRangeZ{-10, -10, "-10"}, - mulRangeZ{0, -1, "1"}, // empty range - mulRangeZ{-1, -100, "1"}, // empty range - mulRangeZ{-1, 1, "0"}, // range includes 0 - mulRangeZ{-1e9, 0, "0"}, // range includes 0 - mulRangeZ{-1e9, 1e9, "0"}, // range includes 0 - mulRangeZ{-10, -1, "3628800"}, // 10! - mulRangeZ{-20, -2, "-2432902008176640000"}, // -20! - mulRangeZ{-99, -1, + {-1, 1, "0"}, + {-2, -1, "2"}, + {-3, -2, "6"}, + {-3, -1, "-6"}, + {1, 3, "6"}, + {-10, -10, "-10"}, + {0, -1, "1"}, // empty range + {-1, -100, "1"}, // empty range + {-1, 1, "0"}, // range includes 0 + {-1e9, 0, "0"}, // range includes 0 + {-1e9, 1e9, "0"}, // range includes 0 + {-10, -1, "3628800"}, // 10! + {-20, -2, "-2432902008176640000"}, // -20! + {-99, -1, "-933262154439441526816992388562667004907159682643816214685929" + "638952175999932299156089414639761565182862536979208272237582" + "511852109168640000000000000000000000", // -99! @@ -205,50 +231,52 @@ func TestMulRangeZ(t *testing.T) { } -type stringTest struct { +var stringTests = []struct { in string out string base int val int64 ok bool -} - - -var stringTests = []stringTest{ - stringTest{in: "", ok: false}, - stringTest{in: "a", ok: false}, - stringTest{in: "z", ok: false}, - stringTest{in: "+", ok: false}, - stringTest{in: "0b", ok: false}, - stringTest{in: "0x", ok: false}, - stringTest{in: "2", base: 2, ok: false}, - stringTest{in: "0b2", base: 0, ok: false}, - stringTest{in: "08", ok: false}, - stringTest{in: "8", base: 8, ok: false}, - stringTest{in: "0xg", base: 0, ok: false}, - stringTest{in: "g", base: 16, ok: false}, - stringTest{"0", "0", 0, 0, true}, - stringTest{"0", "0", 10, 0, true}, - stringTest{"0", "0", 16, 0, true}, - stringTest{"10", "10", 0, 10, true}, - stringTest{"10", "10", 10, 10, true}, - stringTest{"10", "10", 16, 16, true}, - stringTest{"-10", "-10", 16, -16, true}, - stringTest{"0x10", "16", 0, 16, true}, - stringTest{in: "0x10", base: 16, ok: false}, - stringTest{"-0x10", "-16", 0, -16, true}, - stringTest{"00", "0", 0, 0, true}, - stringTest{"0", "0", 8, 0, true}, - stringTest{"07", "7", 0, 7, true}, - stringTest{"7", "7", 8, 7, true}, - stringTest{"023", "19", 0, 19, true}, - stringTest{"23", "23", 8, 19, true}, - stringTest{"cafebabe", "cafebabe", 16, 0xcafebabe, true}, - stringTest{"0b0", "0", 0, 0, true}, - stringTest{"-111", "-111", 2, -7, true}, - stringTest{"-0b111", "-7", 0, -7, true}, - stringTest{"0b1001010111", "599", 0, 0x257, true}, - stringTest{"1001010111", "1001010111", 2, 0x257, true}, +}{ + {in: "", ok: false}, + {in: "a", ok: false}, + {in: "z", ok: false}, + {in: "+", ok: false}, + {in: "-", ok: false}, + {in: "0b", ok: false}, + {in: "0x", ok: false}, + {in: "2", base: 2, ok: false}, + {in: "0b2", base: 0, ok: false}, + {in: "08", ok: false}, + {in: "8", base: 8, ok: false}, + {in: "0xg", base: 0, ok: false}, + {in: "g", base: 16, ok: false}, + {"0", "0", 0, 0, true}, + {"0", "0", 10, 0, true}, + {"0", "0", 16, 0, true}, + {"+0", "0", 0, 0, true}, + {"-0", "0", 0, 0, true}, + {"10", "10", 0, 10, true}, + {"10", "10", 10, 10, true}, + {"10", "10", 16, 16, true}, + {"-10", "-10", 16, -16, true}, + {"+10", "10", 16, 16, true}, + {"0x10", "16", 0, 16, true}, + {in: "0x10", base: 16, ok: false}, + {"-0x10", "-16", 0, -16, true}, + {"+0x10", "16", 0, 16, true}, + {"00", "0", 0, 0, true}, + {"0", "0", 8, 0, true}, + {"07", "7", 0, 7, true}, + {"7", "7", 8, 7, true}, + {"023", "19", 0, 19, true}, + {"23", "23", 8, 19, true}, + {"cafebabe", "cafebabe", 16, 0xcafebabe, true}, + {"0b0", "0", 0, 0, true}, + {"-111", "-111", 2, -7, true}, + {"-0b111", "-7", 0, -7, true}, + {"0b1001010111", "599", 0, 0x257, true}, + {"1001010111", "1001010111", 2, 0x257, true}, } @@ -276,13 +304,13 @@ func TestGetString(t *testing.T) { if test.base == 10 { s := z.String() if s != test.out { - t.Errorf("#%da got %s; want %s\n", i, s, test.out) + t.Errorf("#%da got %s; want %s", i, s, test.out) } } s := fmt.Sprintf(format(test.base), z) if s != test.out { - t.Errorf("#%db got %s; want %s\n", i, s, test.out) + t.Errorf("#%db got %s; want %s", i, s, test.out) } } } @@ -310,30 +338,27 @@ func TestSetString(t *testing.T) { } if n1.Cmp(expected) != 0 { - t.Errorf("#%d (input '%s') got: %s want: %d\n", i, test.in, n1, test.val) + t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val) } if n2.Cmp(expected) != 0 { - t.Errorf("#%d (input '%s') got: %s want: %d\n", i, test.in, n2, test.val) + t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val) } } } -type divisionSignsTest struct { +// Examples from the Go Language Spec, section "Arithmetic operators" +var divisionSignsTests = []struct { x, y int64 q, r int64 // T-division d, m int64 // Euclidian division -} - - -// Examples from the Go Language Spec, section "Arithmetic operators" -var divisionSignsTests = []divisionSignsTest{ - divisionSignsTest{5, 3, 1, 2, 1, 2}, - divisionSignsTest{-5, 3, -1, -2, -2, 1}, - divisionSignsTest{5, -3, -1, 2, -1, 2}, - divisionSignsTest{-5, -3, 1, -2, 2, 1}, - divisionSignsTest{1, 2, 0, 1, 0, 1}, - divisionSignsTest{8, 4, 2, 0, 2, 0}, +}{ + {5, 3, 1, 2, 1, 2}, + {-5, 3, -1, -2, -2, 1}, + {5, -3, -1, 2, -1, 2}, + {-5, -3, 1, -2, 2, 1}, + {1, 2, 0, 1, 0, 1}, + {8, 4, 2, 0, 2, 0}, } @@ -454,20 +479,17 @@ func checkQuo(x, y []byte) bool { } -type quoTest struct { +var quoTests = []struct { x, y string q, r string -} - - -var quoTests = []quoTest{ - quoTest{ +}{ + { "476217953993950760840509444250624797097991362735329973741718102894495832294430498335824897858659711275234906400899559094370964723884706254265559534144986498357", "9353930466774385905609975137998169297361893554149986716853295022578535724979483772383667534691121982974895531435241089241440253066816724367338287092081996", "50911", "1", }, - quoTest{ + { "11510768301994997771168", "1328165573307167369775", "8", @@ -517,25 +539,22 @@ func TestQuoStepD6(t *testing.T) { } -type bitLenTest struct { +var bitLenTests = []struct { in string out int -} - - -var bitLenTests = []bitLenTest{ - bitLenTest{"-1", 1}, - bitLenTest{"0", 0}, - bitLenTest{"1", 1}, - bitLenTest{"2", 2}, - bitLenTest{"4", 3}, - bitLenTest{"0xabc", 12}, - bitLenTest{"0x8000", 16}, - bitLenTest{"0x80000000", 32}, - bitLenTest{"0x800000000000", 48}, - bitLenTest{"0x8000000000000000", 64}, - bitLenTest{"0x80000000000000000000", 80}, - bitLenTest{"-0x4000000000000000000000", 87}, +}{ + {"-1", 1}, + {"0", 0}, + {"1", 1}, + {"2", 2}, + {"4", 3}, + {"0xabc", 12}, + {"0x8000", 16}, + {"0x80000000", 32}, + {"0x800000000000", 48}, + {"0x8000000000000000", 64}, + {"0x80000000000000000000", 80}, + {"-0x4000000000000000000000", 87}, } @@ -548,32 +567,29 @@ func TestBitLen(t *testing.T) { } if n := x.BitLen(); n != test.out { - t.Errorf("#%d got %d want %d\n", i, n, test.out) + t.Errorf("#%d got %d want %d", i, n, test.out) } } } -type expTest struct { +var expTests = []struct { x, y, m string out string -} - - -var expTests = []expTest{ - expTest{"5", "0", "", "1"}, - expTest{"-5", "0", "", "-1"}, - expTest{"5", "1", "", "5"}, - expTest{"-5", "1", "", "-5"}, - expTest{"-2", "3", "2", "0"}, - expTest{"5", "2", "", "25"}, - expTest{"1", "65537", "2", "1"}, - expTest{"0x8000000000000000", "2", "", "0x40000000000000000000000000000000"}, - expTest{"0x8000000000000000", "2", "6719", "4944"}, - expTest{"0x8000000000000000", "3", "6719", "5447"}, - expTest{"0x8000000000000000", "1000", "6719", "1603"}, - expTest{"0x8000000000000000", "1000000", "6719", "3199"}, - expTest{ +}{ + {"5", "0", "", "1"}, + {"-5", "0", "", "-1"}, + {"5", "1", "", "5"}, + {"-5", "1", "", "-5"}, + {"-2", "3", "2", "0"}, + {"5", "2", "", "25"}, + {"1", "65537", "2", "1"}, + {"0x8000000000000000", "2", "", "0x40000000000000000000000000000000"}, + {"0x8000000000000000", "2", "6719", "4944"}, + {"0x8000000000000000", "3", "6719", "5447"}, + {"0x8000000000000000", "1000", "6719", "1603"}, + {"0x8000000000000000", "1000000", "6719", "3199"}, + { "2938462938472983472983659726349017249287491026512746239764525612965293865296239471239874193284792387498274256129746192347", "298472983472983471903246121093472394872319615612417471234712061", "29834729834729834729347290846729561262544958723956495615629569234729836259263598127342374289365912465901365498236492183464", @@ -630,14 +646,11 @@ func checkGcd(aBytes, bBytes []byte) bool { } -type gcdTest struct { +var gcdTests = []struct { a, b int64 d, x, y int64 -} - - -var gcdTests = []gcdTest{ - gcdTest{120, 23, 1, -9, 47}, +}{ + {120, 23, 1, -9, 47}, } @@ -726,30 +739,30 @@ type intShiftTest struct { var rshTests = []intShiftTest{ - intShiftTest{"0", 0, "0"}, - intShiftTest{"-0", 0, "0"}, - intShiftTest{"0", 1, "0"}, - intShiftTest{"0", 2, "0"}, - intShiftTest{"1", 0, "1"}, - intShiftTest{"1", 1, "0"}, - intShiftTest{"1", 2, "0"}, - intShiftTest{"2", 0, "2"}, - intShiftTest{"2", 1, "1"}, - intShiftTest{"-1", 0, "-1"}, - intShiftTest{"-1", 1, "-1"}, - intShiftTest{"-1", 10, "-1"}, - intShiftTest{"-100", 2, "-25"}, - intShiftTest{"-100", 3, "-13"}, - intShiftTest{"-100", 100, "-1"}, - intShiftTest{"4294967296", 0, "4294967296"}, - intShiftTest{"4294967296", 1, "2147483648"}, - intShiftTest{"4294967296", 2, "1073741824"}, - intShiftTest{"18446744073709551616", 0, "18446744073709551616"}, - intShiftTest{"18446744073709551616", 1, "9223372036854775808"}, - intShiftTest{"18446744073709551616", 2, "4611686018427387904"}, - intShiftTest{"18446744073709551616", 64, "1"}, - intShiftTest{"340282366920938463463374607431768211456", 64, "18446744073709551616"}, - intShiftTest{"340282366920938463463374607431768211456", 128, "1"}, + {"0", 0, "0"}, + {"-0", 0, "0"}, + {"0", 1, "0"}, + {"0", 2, "0"}, + {"1", 0, "1"}, + {"1", 1, "0"}, + {"1", 2, "0"}, + {"2", 0, "2"}, + {"2", 1, "1"}, + {"-1", 0, "-1"}, + {"-1", 1, "-1"}, + {"-1", 10, "-1"}, + {"-100", 2, "-25"}, + {"-100", 3, "-13"}, + {"-100", 100, "-1"}, + {"4294967296", 0, "4294967296"}, + {"4294967296", 1, "2147483648"}, + {"4294967296", 2, "1073741824"}, + {"18446744073709551616", 0, "18446744073709551616"}, + {"18446744073709551616", 1, "9223372036854775808"}, + {"18446744073709551616", 2, "4611686018427387904"}, + {"18446744073709551616", 64, "1"}, + {"340282366920938463463374607431768211456", 64, "18446744073709551616"}, + {"340282366920938463463374607431768211456", 128, "1"}, } @@ -786,25 +799,25 @@ func TestRshSelf(t *testing.T) { var lshTests = []intShiftTest{ - intShiftTest{"0", 0, "0"}, - intShiftTest{"0", 1, "0"}, - intShiftTest{"0", 2, "0"}, - intShiftTest{"1", 0, "1"}, - intShiftTest{"1", 1, "2"}, - intShiftTest{"1", 2, "4"}, - intShiftTest{"2", 0, "2"}, - intShiftTest{"2", 1, "4"}, - intShiftTest{"2", 2, "8"}, - intShiftTest{"-87", 1, "-174"}, - intShiftTest{"4294967296", 0, "4294967296"}, - intShiftTest{"4294967296", 1, "8589934592"}, - intShiftTest{"4294967296", 2, "17179869184"}, - intShiftTest{"18446744073709551616", 0, "18446744073709551616"}, - intShiftTest{"9223372036854775808", 1, "18446744073709551616"}, - intShiftTest{"4611686018427387904", 2, "18446744073709551616"}, - intShiftTest{"1", 64, "18446744073709551616"}, - intShiftTest{"18446744073709551616", 64, "340282366920938463463374607431768211456"}, - intShiftTest{"1", 128, "340282366920938463463374607431768211456"}, + {"0", 0, "0"}, + {"0", 1, "0"}, + {"0", 2, "0"}, + {"1", 0, "1"}, + {"1", 1, "2"}, + {"1", 2, "4"}, + {"2", 0, "2"}, + {"2", 1, "4"}, + {"2", 2, "8"}, + {"-87", 1, "-174"}, + {"4294967296", 0, "4294967296"}, + {"4294967296", 1, "8589934592"}, + {"4294967296", 2, "17179869184"}, + {"18446744073709551616", 0, "18446744073709551616"}, + {"9223372036854775808", 1, "18446744073709551616"}, + {"4611686018427387904", 2, "18446744073709551616"}, + {"1", 64, "18446744073709551616"}, + {"18446744073709551616", 64, "340282366920938463463374607431768211456"}, + {"1", 128, "340282366920938463463374607431768211456"}, } @@ -894,26 +907,24 @@ func TestInt64(t *testing.T) { } -type bitwiseTest struct { +var bitwiseTests = []struct { x, y string and, or, xor, andNot string -} - -var bitwiseTests = []bitwiseTest{ - bitwiseTest{"0x00", "0x00", "0x00", "0x00", "0x00", "0x00"}, - bitwiseTest{"0x00", "0x01", "0x00", "0x01", "0x01", "0x00"}, - bitwiseTest{"0x01", "0x00", "0x00", "0x01", "0x01", "0x01"}, - bitwiseTest{"-0x01", "0x00", "0x00", "-0x01", "-0x01", "-0x01"}, - bitwiseTest{"-0xAF", "-0x50", "0x00", "-0xFF", "-0x01", "-0x01"}, - bitwiseTest{"0x00", "-0x01", "0x00", "-0x01", "-0x01", "0x00"}, - bitwiseTest{"0x01", "0x01", "0x01", "0x01", "0x00", "0x00"}, - bitwiseTest{"-0x01", "-0x01", "-0x01", "-0x01", "0x00", "0x00"}, - bitwiseTest{"0x07", "0x08", "0x00", "0x0f", "0x0f", "0x07"}, - bitwiseTest{"0x05", "0x0f", "0x05", "0x0f", "0x0a", "0x00"}, - bitwiseTest{"0x013ff6", "0x9a4e", "0x1a46", "0x01bffe", "0x01a5b8", "0x0125b0"}, - bitwiseTest{"-0x013ff6", "0x9a4e", "0x800a", "-0x0125b2", "-0x01a5bc", "-0x01c000"}, - bitwiseTest{"-0x013ff6", "-0x9a4e", "-0x01bffe", "-0x1a46", "0x01a5b8", "0x8008"}, - bitwiseTest{ +}{ + {"0x00", "0x00", "0x00", "0x00", "0x00", "0x00"}, + {"0x00", "0x01", "0x00", "0x01", "0x01", "0x00"}, + {"0x01", "0x00", "0x00", "0x01", "0x01", "0x01"}, + {"-0x01", "0x00", "0x00", "-0x01", "-0x01", "-0x01"}, + {"-0xaf", "-0x50", "-0xf0", "-0x0f", "0xe1", "0x41"}, + {"0x00", "-0x01", "0x00", "-0x01", "-0x01", "0x00"}, + {"0x01", "0x01", "0x01", "0x01", "0x00", "0x00"}, + {"-0x01", "-0x01", "-0x01", "-0x01", "0x00", "0x00"}, + {"0x07", "0x08", "0x00", "0x0f", "0x0f", "0x07"}, + {"0x05", "0x0f", "0x05", "0x0f", "0x0a", "0x00"}, + {"0x013ff6", "0x9a4e", "0x1a46", "0x01bffe", "0x01a5b8", "0x0125b0"}, + {"-0x013ff6", "0x9a4e", "0x800a", "-0x0125b2", "-0x01a5bc", "-0x01c000"}, + {"-0x013ff6", "-0x9a4e", "-0x01bffe", "-0x1a46", "0x01a5b8", "0x8008"}, + { "0x1000009dc6e3d9822cba04129bcbe3401", "0xb9bd7d543685789d57cb918e833af352559021483cdb05cc21fd", "0x1000001186210100001000009048c2001", @@ -921,7 +932,7 @@ var bitwiseTests = []bitwiseTest{ "0xb9bd7d543685789d57ca918e8ae69d6fcdb2eae87df2b97215fc", "0x8c40c2d8822caa04120b8321400", }, - bitwiseTest{ + { "0x1000009dc6e3d9822cba04129bcbe3401", "-0xb9bd7d543685789d57cb918e833af352559021483cdb05cc21fd", "0x8c40c2d8822caa04120b8321401", @@ -929,7 +940,7 @@ var bitwiseTests = []bitwiseTest{ "-0xb9bd7d543685789d57ca918e8ae69d6fcdb2eae87df2b97215fe", "0x1000001186210100001000009048c2000", }, - bitwiseTest{ + { "-0x1000009dc6e3d9822cba04129bcbe3401", "-0xb9bd7d543685789d57cb918e833af352559021483cdb05cc21fd", "-0xb9bd7d543685789d57cb918e8bfeff7fddb2ebe87dfbbdfe35fd", @@ -944,24 +955,24 @@ type bitFun func(z, x, y *Int) *Int func testBitFun(t *testing.T, msg string, f bitFun, x, y *Int, exp string) { expected := new(Int) - expected.SetString(exp, 16) + expected.SetString(exp, 0) out := f(new(Int), x, y) if out.Cmp(expected) != 0 { - println("Test failed") t.Errorf("%s: got %s want %s", msg, out, expected) } } func testBitFunSelf(t *testing.T, msg string, f bitFun, x, y *Int, exp string) { + self := new(Int) + self.Set(x) expected := new(Int) - expected.SetString(exp, 16) + expected.SetString(exp, 0) - x = f(x, x, y) - if x.Cmp(expected) != 0 { - println("Test failed") - t.Errorf("%s: got %s want %s", msg, x, expected) + self = f(self, self, y) + if self.Cmp(expected) != 0 { + t.Errorf("%s: got %s want %s", msg, self, expected) } } @@ -970,8 +981,8 @@ func TestBitwise(t *testing.T) { x := new(Int) y := new(Int) for _, test := range bitwiseTests { - x.SetString(test.x, 16) - y.SetString(test.y, 16) + x.SetString(test.x, 0) + y.SetString(test.y, 0) testBitFun(t, "and", (*Int).And, x, y, test.and) testBitFunSelf(t, "and", (*Int).And, x, y, test.and) @@ -985,18 +996,16 @@ func TestBitwise(t *testing.T) { } -type notTest struct { +var notTests = []struct { in string out string -} - -var notTests = []notTest{ - notTest{"0", "-1"}, - notTest{"1", "-2"}, - notTest{"7", "-8"}, - notTest{"0", "-1"}, - notTest{"-81910", "81909"}, - notTest{ +}{ + {"0", "-1"}, + {"1", "-2"}, + {"7", "-8"}, + {"0", "-1"}, + {"-81910", "81909"}, + { "298472983472983471903246121093472394872319615612417471234712061", "-298472983472983471903246121093472394872319615612417471234712062", }, @@ -1021,15 +1030,13 @@ func TestNot(t *testing.T) { } -type modInverseTest struct { +var modInverseTests = []struct { element string prime string -} - -var modInverseTests = []modInverseTest{ - modInverseTest{"1", "7"}, - modInverseTest{"1", "13"}, - modInverseTest{"239487239847", "2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919"}, +}{ + {"1", "7"}, + {"1", "13"}, + {"239487239847", "2410312426921032588552076022197566074856950548502459942654116941958108831682612228890093858261341614673227141477904012196503648957050582631942730706805009223062734745341073406696246014589361659774041027169249453200378729434170325843778659198143763193776859869524088940195577346119843545301547043747207749969763750084308926339295559968882457872412993810129130294592999947926365264059284647209730384947211681434464714438488520940127459844288859336526896320919633919"}, } func TestModInverse(t *testing.T) { |