OSDN Git Service

new repo
[bytom/vapor.git] / common / big_test.go
1 // Copyright 2014 The go-ethereum Authors
2 // This file is part of the go-ethereum library.
3 //
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.
8 //
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.
13 //
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/>.
16
17 package common
18
19 import (
20         "bytes"
21         "testing"
22 )
23
24 func TestMisc(t *testing.T) {
25         a := Big("10")
26         b := Big("57896044618658097711785492504343953926634992332820282019728792003956564819968")
27         c := []byte{1, 2, 3, 4}
28         z := BitTest(a, 1)
29
30         if z != true {
31                 t.Error("Expected true got", z)
32         }
33
34         U256(a)
35         S256(a)
36
37         U256(b)
38         S256(b)
39
40         BigD(c)
41 }
42
43 func TestBigMax(t *testing.T) {
44         a := Big("10")
45         b := Big("5")
46
47         max1 := BigMax(a, b)
48         if max1 != a {
49                 t.Errorf("Expected %d got %d", a, max1)
50         }
51
52         max2 := BigMax(b, a)
53         if max2 != a {
54                 t.Errorf("Expected %d got %d", a, max2)
55         }
56 }
57
58 func TestBigMin(t *testing.T) {
59         a := Big("10")
60         b := Big("5")
61
62         min1 := BigMin(a, b)
63         if min1 != b {
64                 t.Errorf("Expected %d got %d", b, min1)
65         }
66
67         min2 := BigMin(b, a)
68         if min2 != b {
69                 t.Errorf("Expected %d got %d", b, min2)
70         }
71 }
72
73 func TestBigCopy(t *testing.T) {
74         a := Big("10")
75         b := BigCopy(a)
76         c := Big("1000000000000")
77         y := BigToBytes(b, 16)
78         ybytes := []byte{0, 10}
79         z := BigToBytes(c, 16)
80         zbytes := []byte{232, 212, 165, 16, 0}
81
82         if bytes.Compare(y, ybytes) != 0 {
83                 t.Error("Got", ybytes)
84         }
85
86         if bytes.Compare(z, zbytes) != 0 {
87                 t.Error("Got", zbytes)
88         }
89 }