|
@ -1,6 +1,7 @@ |
|
|
package common |
|
|
package common |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"fmt" |
|
|
"math/big" |
|
|
"math/big" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
@ -61,20 +62,28 @@ func TestExpectError(t *testing.T) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func TestNewFloat40Floor(t *testing.T) { |
|
|
func TestNewFloat40Floor(t *testing.T) { |
|
|
testVector := map[string][]uint64{ |
|
|
|
|
|
|
|
|
testVector := map[string][]string{ |
|
|
// []int contains [Float40 value, Flot40 Floor value], when
|
|
|
// []int contains [Float40 value, Flot40 Floor value], when
|
|
|
// Float40 value is expected to be 0, is because is expected to
|
|
|
// Float40 value is expected to be 0, is because is expected to
|
|
|
// be an error
|
|
|
// be an error
|
|
|
"9922334455000000000000000000000000000000": {1040714485495, 1040714485495}, |
|
|
|
|
|
"9922334455000000000000000000000000000001": {0, 6846188881046405121}, |
|
|
|
|
|
"9922334454999999999999999999999999999999": {0, 6846188881046405119}, |
|
|
|
|
|
"42949672950000000000000000000000000000000": {1069446856703, 1069446856703}, |
|
|
|
|
|
"99223344556573838487575": {0, 16754928163869896727}, |
|
|
|
|
|
"992233445500000000000000000000000000000000": {0, 0}, |
|
|
|
|
|
"343597383670000000000000000000000000000000": {1099511627775, 1099511627775}, |
|
|
|
|
|
"343597383680000000000000000000000000000000": {0, 1099511627776}, |
|
|
|
|
|
"343597383690000000000000000000000000000000": {0, 1099511627777}, |
|
|
|
|
|
"343597383700000000000000000000000000000000": {0, 0}, |
|
|
|
|
|
|
|
|
"9922334455000000000000000000000000000000": { |
|
|
|
|
|
"1040714485495", "1040714485495", "9922334455000000000000000000000000000000"}, |
|
|
|
|
|
"9922334455000000000000000000000000000001": { // Floor [2] will be same as prev line
|
|
|
|
|
|
"0", "1040714485495", "9922334455000000000000000000000000000000"}, |
|
|
|
|
|
"9922334454999999999999999999999999999999": { |
|
|
|
|
|
"0", "1040714485494", "9922334454000000000000000000000000000000"}, |
|
|
|
|
|
"42949672950000000000000000000000000000000": { |
|
|
|
|
|
"1069446856703", "1069446856703", "42949672950000000000000000000000000000000"}, |
|
|
|
|
|
"99223344556573838487575": { |
|
|
|
|
|
"0", "456598933239", "99223344550000000000000"}, |
|
|
|
|
|
"992233445500000000000000000000000000000000": { |
|
|
|
|
|
"0", "0", "0"}, // e>31, returns 0, err
|
|
|
|
|
|
"343597383670000000000000000000000000000000": { |
|
|
|
|
|
"1099511627775", "1099511627775", "343597383670000000000000000000000000000000"}, |
|
|
|
|
|
"343597383680000000000000000000000000000000": { |
|
|
|
|
|
"0", "0", "0"}, // e>31, returns 0, err
|
|
|
|
|
|
"1157073197879933027": { |
|
|
|
|
|
"0", "286448638922", "1157073197800000000"}, |
|
|
} |
|
|
} |
|
|
for test := range testVector { |
|
|
for test := range testVector { |
|
|
bi, ok := new(big.Int).SetString(test, 10) |
|
|
bi, ok := new(big.Int).SetString(test, 10) |
|
@ -85,7 +94,7 @@ func TestNewFloat40Floor(t *testing.T) { |
|
|
} else { |
|
|
} else { |
|
|
assert.NoError(t, err) |
|
|
assert.NoError(t, err) |
|
|
} |
|
|
} |
|
|
assert.Equal(t, testVector[test][0], uint64(f40)) |
|
|
|
|
|
|
|
|
assert.Equal(t, testVector[test][0], fmt.Sprint(uint64(f40))) |
|
|
|
|
|
|
|
|
f40, err = NewFloat40Floor(bi) |
|
|
f40, err = NewFloat40Floor(bi) |
|
|
if f40 == 0 { |
|
|
if f40 == 0 { |
|
@ -93,7 +102,11 @@ func TestNewFloat40Floor(t *testing.T) { |
|
|
} else { |
|
|
} else { |
|
|
assert.NoError(t, err) |
|
|
assert.NoError(t, err) |
|
|
} |
|
|
} |
|
|
assert.Equal(t, testVector[test][1], uint64(f40)) |
|
|
|
|
|
|
|
|
assert.Equal(t, testVector[test][1], fmt.Sprint(uint64(f40))) |
|
|
|
|
|
|
|
|
|
|
|
bi2, err := f40.BigInt() |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
assert.Equal(t, fmt.Sprint(testVector[test][2]), bi2.String()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|