1 // Copyright 2015 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
4 // The go-ethereum library is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // The go-ethereum library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
23 "github.com/vapor/common"
26 func TestSet(t *testing.T) {
30 if a.num.Cmp(b.num) != 0 {
31 t.Error("didn't compare", a, b)
34 c := Uint(0).SetBytes(common.Hex2Bytes("0a"))
35 if c.num.Cmp(big.NewInt(10)) != 0 {
36 t.Error("c set bytes failed.")
40 func TestInitialiser(t *testing.T) {
42 init := NewInitialiser(func(x *Number) *Number {
46 a := init(0).Add(init(1), init(2))
47 if a.Cmp(init(3)) != 0 {
48 t.Error("expected 3. got", a)
51 t.Error("expected limiter to be called")
55 func TestGet(t *testing.T) {
58 t.Error("expected to get 10. got", a.Uint64())
63 t.Error("expected to get 10. got", a.Int64())
67 func TestCmp(t *testing.T) {
73 t.Error("a b == 0 failed", a, b)
77 t.Error("a c < 0 failed", a, c)
81 t.Error("c b > 0 failed", c, b)
85 func TestMaxArith(t *testing.T) {
86 a := Uint(0).Add(MaxUint256, One)
88 t.Error("expected max256 + 1 = 0 got", a)
91 a = Uint(0).Sub(Uint(0), One)
92 if a.Cmp(MaxUint256) != 0 {
93 t.Error("expected 0 - 1 = max256 got", a)
96 a = Int(0).Sub(Int(0), One)
97 if a.Cmp(MinOne) != 0 {
98 t.Error("expected 0 - 1 = -1 got", a)
102 func TestConversion(t *testing.T) {
105 if b.Cmp(MaxUint256) != 0 {
106 t.Error("expected -1 => unsigned to return max. got", b)