|
|
|
@ -277,48 +277,3 @@ func TestLittleEndianByteAt(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestS256(t *testing.T) { |
|
|
|
|
tests := []struct{ x, y *big.Int }{ |
|
|
|
|
{x: big.NewInt(0), y: big.NewInt(0)}, |
|
|
|
|
{x: big.NewInt(1), y: big.NewInt(1)}, |
|
|
|
|
{x: big.NewInt(2), y: big.NewInt(2)}, |
|
|
|
|
{ |
|
|
|
|
x: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)), |
|
|
|
|
y: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
x: BigPow(2, 255), |
|
|
|
|
y: new(big.Int).Neg(BigPow(2, 255)), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(1)), |
|
|
|
|
y: big.NewInt(-1), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(2)), |
|
|
|
|
y: big.NewInt(-2), |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
for _, test := range tests { |
|
|
|
|
if y := S256(test.x); y.Cmp(test.y) != 0 { |
|
|
|
|
t.Errorf("S256(%x) = %x, want %x", test.x, y, test.y) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestExp(t *testing.T) { |
|
|
|
|
tests := []struct{ base, exponent, result *big.Int }{ |
|
|
|
|
{base: big.NewInt(0), exponent: big.NewInt(0), result: big.NewInt(1)}, |
|
|
|
|
{base: big.NewInt(1), exponent: big.NewInt(0), result: big.NewInt(1)}, |
|
|
|
|
{base: big.NewInt(1), exponent: big.NewInt(1), result: big.NewInt(1)}, |
|
|
|
|
{base: big.NewInt(1), exponent: big.NewInt(2), result: big.NewInt(1)}, |
|
|
|
|
{base: big.NewInt(3), exponent: big.NewInt(144), result: MustParseBig256("507528786056415600719754159741696356908742250191663887263627442114881")}, |
|
|
|
|
{base: big.NewInt(2), exponent: big.NewInt(255), result: MustParseBig256("57896044618658097711785492504343953926634992332820282019728792003956564819968")}, |
|
|
|
|
} |
|
|
|
|
for _, test := range tests { |
|
|
|
|
if result := Exp(test.base, test.exponent); result.Cmp(test.result) != 0 { |
|
|
|
|
t.Errorf("Exp(%d, %d) = %d, want %d", test.base, test.exponent, result, test.result) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|