github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/ethutil/big_test.go (about)

     1  package ethutil
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestMisc(t *testing.T) {
     9  	a := Big("10")
    10  	b := Big("57896044618658097711785492504343953926634992332820282019728792003956564819968")
    11  	c := []byte{1, 2, 3, 4}
    12  	z := BitTest(a, 1)
    13  
    14  	if z != true {
    15  		t.Error("Expected true got", z)
    16  	}
    17  
    18  	U256(a)
    19  	S256(a)
    20  
    21  	U256(b)
    22  	S256(b)
    23  
    24  	BigD(c)
    25  }
    26  
    27  func TestBigMax(t *testing.T) {
    28  	a := Big("10")
    29  	b := Big("5")
    30  
    31  	max1 := BigMax(a, b)
    32  	if max1 != a {
    33  		t.Errorf("Expected %d got %d", a, max1)
    34  	}
    35  
    36  	max2 := BigMax(b, a)
    37  	if max2 != a {
    38  		t.Errorf("Expected %d got %d", a, max2)
    39  	}
    40  }
    41  
    42  func TestBigMin(t *testing.T) {
    43  	a := Big("10")
    44  	b := Big("5")
    45  
    46  	min1 := BigMin(a, b)
    47  	if min1 != b {
    48  		t.Errorf("Expected %d got %d", b, min1)
    49  	}
    50  
    51  	min2 := BigMin(b, a)
    52  	if min2 != b {
    53  		t.Errorf("Expected %d got %d", b, min2)
    54  	}
    55  }
    56  
    57  func TestBigCopy(t *testing.T) {
    58  	a := Big("10")
    59  	b := BigCopy(a)
    60  	c := Big("1000000000000")
    61  	y := BigToBytes(b, 16)
    62  	ybytes := []byte{0, 10}
    63  	z := BigToBytes(c, 16)
    64  	zbytes := []byte{232, 212, 165, 16, 0}
    65  
    66  	if bytes.Compare(y, ybytes) != 0 {
    67  		t.Error("Got", ybytes)
    68  	}
    69  
    70  	if bytes.Compare(z, zbytes) != 0 {
    71  		t.Error("Got", zbytes)
    72  	}
    73  }