kaspad/util/btcmath_test.go
Svarog e9ec8cd39c [NOD-142] Convert Height and ChainHeight to uint64 (#269)
* [NOD-142] Updated util.FastLog2Floor to work on uint64

* [NOD-142] Convert height and chainHeight to uint64

* [NOD-142] A couple fixes in comments of TestFastLog2Floor

* [NOD-142] Make spendableOutOffset uint64 too
2019-04-30 12:50:46 +03:00

36 lines
713 B
Go

package util
import (
"testing"
)
func TestFastLog2Floor(t *testing.T) {
tests := []struct {
n uint64
expectedResult uint8
}{
{1, 0},
{2, 1},
{3, 1},
{4, 2},
{5, 2},
{16, 4},
{31, 4},
{1684234, 20},
{4294967295, 31}, // math.MaxUint32 (2^32 - 1)
{4294967296, 32}, // 2^32
{4294967297, 32}, // 2^32 + 1
{4611686018427387904, 62},
{9223372036854775808, 63}, // 2^63
{18446744073709551615, 63}, // math.MaxUint64 (2^64 - 1).
}
for _, test := range tests {
actualResult := FastLog2Floor(test.n)
if test.expectedResult != actualResult {
t.Errorf("TestFastLog2Floor: %d: expected result: %d but got: %d", test.n, test.expectedResult, actualResult)
}
}
}