MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestDigitsLookupTable

Function TestDigitsLookupTable

table_test.go:98–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func 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
143func TestTableExp10(t *testing.T) {
144 tests := []struct {

Callers

nothing calls this directly

Calls 8

StringMethod · 0.95
MulMethod · 0.95
NewBigIntFunction · 0.85
NewWithBigIntFunction · 0.85
NumDigitsMethod · 0.80
SetInt64Method · 0.45
ExpMethod · 0.45
CmpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…