From 12d0933058bee84666b1a42381e04ccaea24b223 Mon Sep 17 00:00:00 2001 From: Denis Bernard Date: Tue, 26 May 2020 02:01:11 +0200 Subject: [PATCH] Fix false positives in tests in i386 --- dec_arith_test.go | 2 +- dec_conv_test.go | 12 ++++++------ dec_test.go | 4 ++-- decimal_test.go | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dec_arith_test.go b/dec_arith_test.go index 24edb54..4eb2b42 100644 --- a/dec_arith_test.go +++ b/dec_arith_test.go @@ -12,7 +12,7 @@ import ( func TestDecDigits(t *testing.T) { for i := 0; i < 10000; i++ { - n := uint(rnd.Uint64()) + n := uint(rnd10W()) d := uint(0) for m := n; m != 0; m /= 10 { d++ diff --git a/dec_conv_test.go b/dec_conv_test.go index 479838d..49b4a3a 100644 --- a/dec_conv_test.go +++ b/dec_conv_test.go @@ -24,8 +24,8 @@ var decStrTests = []struct { {dec{0xc5}, 2, "11000101"}, {dec{03271}, 8, "3271"}, {dec{10}, 10, "10"}, - {dec{1234567890}, 10, "1234567890"}, - {dec{0xdeadbeef}, 16, "deadbeef"}, + {dec{987654321}, 10, "987654321"}, + {dec{0xbadcafe}, 16, "badcafe"}, {dec{0x229be7}, 17, "1a2b3c"}, {dec{0x309663e6}, 32, "o9cov6"}, {dec{0x309663e6}, 62, "TakXI"}, @@ -146,15 +146,15 @@ var decScanTests = []struct { {"0O17", 0, false, dec{017}, 8, 2, nil, 0}, {"03271", 0, false, dec{03271}, 8, 4, nil, 0}, {"10ab", 0, false, dec{10}, 10, 2, nil, 'a'}, - {"1234567890", 0, false, dec{1234567890}, 10, 10, nil, 0}, + {"987654321", 0, false, dec{987654321}, 10, 9, nil, 0}, {"A", 36, false, dec{10}, 36, 1, nil, 0}, {"A", 37, false, dec{36}, 37, 1, nil, 0}, {"xyz", 36, false, dec{(33*36+34)*36 + 35}, 36, 3, nil, 0}, {"XYZ?", 36, false, dec{(33*36+34)*36 + 35}, 36, 3, nil, '?'}, {"XYZ?", 62, false, dec{(59*62+60)*62 + 61}, 62, 3, nil, '?'}, {"0x", 16, false, nil, 16, 1, nil, 'x'}, - {"0xdeadbeef", 0, false, dec{0xdeadbeef}, 16, 8, nil, 0}, - {"0XDEADBEEF", 0, false, dec{0xdeadbeef}, 16, 8, nil, 0}, + {"0xbadcafe", 0, false, dec{0xbadcafe}, 16, 7, nil, 0}, + {"0XBADCAFE", 0, false, dec{0xbadcafe}, 16, 7, nil, 0}, // valid, with decimal point {"0.", 0, false, nil, 10, 1, nil, '.'}, @@ -170,7 +170,7 @@ var decScanTests = []struct { {"0B0.12", 0, true, dec{1}, 2, -1, nil, '2'}, {"0o0.7", 0, true, dec{7}, 8, -1, nil, 0}, {"0O0.78", 0, true, dec{7}, 8, -1, nil, '8'}, - {"0xdead.beef", 0, true, dec{0xdeadbeef}, 16, -4, nil, 0}, + {"0xbad.beef", 0, true, dec{0xbadbeef}, 16, -4, nil, 0}, // valid, with separators {"1_000", 0, false, dec{1000}, 10, 4, nil, 0}, diff --git a/dec_test.go b/dec_test.go index 6cf1c0b..a847ffd 100644 --- a/dec_test.go +++ b/dec_test.go @@ -48,9 +48,9 @@ type decArgNN struct { var decSumNN = []decArgNN{ {}, {dec{1}, nil, dec{1}}, - {dec{1111111110}, dec{123456789}, dec{987654321}}, + {dec{111111110}, dec{23456789}, dec{87654321}}, {dec{0, 0, 0, 1}, nil, dec{0, 0, 0, 1}}, - {dec{0, 0, 0, 1111111110}, dec{0, 0, 0, 123456789}, dec{0, 0, 0, 987654321}}, + {dec{0, 0, 0, 111111110}, dec{0, 0, 0, 23456789}, dec{0, 0, 0, 87654321}}, {dec{0, 0, 0, 1}, dec{0, 0, _DMax}, dec{0, 0, 1}}, } diff --git a/decimal_test.go b/decimal_test.go index c0e0348..d998e79 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -622,9 +622,9 @@ func TestDecimalSetUint64(t *testing.T) { for prec := uint(1); prec <= mp; prec++ { f := new(Decimal).SetPrec(prec).SetMode(ToZero).SetUint64(x) got := f.uint64() - want := x - x%uint64(pow10(mp-prec)) // cut off (round to zero) low prec digits + want := x - x%pow10tab[mp-prec] // cut off (round to zero) low prec digits if got != want { - t.Errorf("got %#x (%s); want %#x", got, f.Text('p', 0), want) + t.Errorf("got %d (%s, prec %d); want %d", got, f.Text('p', 0), prec, want) } } } @@ -658,9 +658,9 @@ func TestDecimalSetInt64(t *testing.T) { for prec := uint(1); prec <= mp; prec++ { f := new(Decimal).SetPrec(prec).SetMode(ToZero).SetInt64(x) got := f.int64() - want := x - x%int64(pow10(mp-prec)) // cut off (round to zero) low prec digits + want := x - x%int64(pow10tab[mp-prec]) // cut off (round to zero) low prec digits if got != want { - t.Errorf("got %#x (%s); want %#x", got, f.Text('p', 0), want) + t.Errorf("got %d (%s, prec %d); want %d", got, f.Text('p', 0), prec, want) } } }