(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestDigitsLookupTable(t *testing.T) { |
| 99 | // Make sure all elements in table make sense. |
| 100 | min := new(BigInt) |
| 101 | prevBorder := NewBigInt(0) |
| 102 | for i := 1; i <= digitsTableSize; i++ { |
| 103 | elem := &digitsLookupTable[i] |
| 104 | |
| 105 | min.SetInt64(2) |
| 106 | min.Exp(min, NewBigInt(int64(i-1)), nil) |
| 107 | if minLen := int64(len(min.String())); minLen != elem.digits { |
| 108 | t.Errorf("expected 2^%d to have %d digits, found %d", i, elem.digits, minLen) |
| 109 | } |
| 110 | |
| 111 | if zeros := int64(strings.Count(elem.border.String(), "0")); zeros != elem.digits { |
| 112 | t.Errorf("the %d digits for digitsLookupTable[%d] does not agree with the border %v", elem.digits, i, &elem.border) |
| 113 | } |
| 114 | |
| 115 | if min.Cmp(&elem.border) >= 0 { |
| 116 | t.Errorf("expected 2^%d = %v to be less than the border, found %v", i-1, min, &elem.border) |
| 117 | } |
| 118 | |
| 119 | if elem.border.Cmp(prevBorder) > 0 { |
| 120 | if min.Cmp(prevBorder) <= 0 { |
| 121 | t.Errorf("expected 2^%d = %v to be greater than or equal to the border, found %v", i-1, min, prevBorder) |
| 122 | } |
| 123 | prevBorder = &elem.border |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Throw random big.Ints at the table and make sure the |
| 128 | // digit lengths line up. |
| 129 | const randomTrials = 100 |
| 130 | for i := 0; i < randomTrials; i++ { |
| 131 | a := NewBigInt(rand.Int63()) |
| 132 | b := NewBigInt(rand.Int63()) |
| 133 | a.Mul(a, b) |
| 134 | |
| 135 | d := NewWithBigInt(a, 0) |
| 136 | tableDigits := d.NumDigits() |
| 137 | if actualDigits := int64(len(a.String())); actualDigits != tableDigits { |
| 138 | t.Errorf("expected %d digits for %v, found %d", tableDigits, a, actualDigits) |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | func TestTableExp10(t *testing.T) { |
| 144 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…