aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2012-01-26 10:08:21 -0800
committerRobert Griesemer <gri@golang.org>2012-01-26 10:08:21 -0800
commit8a90a8861f66525fed7f4b5e8d5499af0248806a (patch)
treefcf067cc55c2899c7edf51738b9116dba88eb4f2
parent71b1c6d3c98b0f34070be4c8f5e9d4c0cb2731ac (diff)
downloadgo-8a90a8861f66525fed7f4b5e8d5499af0248806a.tar.gz
go-8a90a8861f66525fed7f4b5e8d5499af0248806a.zip
math/big: test both bitLen and bitLen_g
Also: simpler, more direct test. R=golang-dev, dave.andersen CC=golang-dev https://golang.org/cl/5573070
-rw-r--r--src/pkg/math/big/arith_test.go30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/pkg/math/big/arith_test.go b/src/pkg/math/big/arith_test.go
index cd02ba3674..c7e3d284c2 100644
--- a/src/pkg/math/big/arith_test.go
+++ b/src/pkg/math/big/arith_test.go
@@ -334,29 +334,21 @@ func TestMulAddWWW(t *testing.T) {
}
}
-func TestWordBitLen(t *testing.T) {
- // Test every possible output of bitLen with the high bit set
- // and then with all bits below max set
- z := bitLen(0)
- if z != 0 {
- t.Errorf("0 got %d want 0", z)
- }
- x := Word(1) // Will be ...00010000...
- y := Word(1) // Will be ...00011111...
- for i := 1; i <= _W; i++ {
- z = bitLen(x)
- if z != i {
- t.Errorf("%x got %d want %d", x, z, i)
- }
- z = bitLen(y)
- if z != i {
- t.Errorf("%x got %d want %d", y, z, i)
+func testWordBitLen(t *testing.T, fname string, f func(Word) int) {
+ for i := 0; i <= _W; i++ {
+ x := Word(1) << uint(i-1) // i == 0 => x == 0
+ n := f(x)
+ if n != i {
+ t.Errorf("got %d; want %d for %s(%#x)", n, i, fname, x)
}
- x <<= 1
- y = (y << 1) | 0x1
}
}
+func TestWordBitLen(t *testing.T) {
+ testWordBitLen(t, "bitLen", bitLen)
+ testWordBitLen(t, "bitLen_g", bitLen_g)
+}
+
// runs b.N iterations of bitLen called on a Word containing (1 << nbits)-1.
func benchmarkBitLenN(b *testing.B, nbits uint) {
testword := Word((uint64(1) << nbits) - 1)