diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2014-11-15 05:01:52 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2014-11-15 05:01:52 +0800 |
commit | 2a9fc7baa908d64ff1ddae44641024114d3ec88d (patch) | |
tree | 7b94082bd16765984046fa3c04c2ed57812d8c89 /ethutil/value_test.go | |
parent | 56aa24002de357c24a9644a49d5702c8d4663909 (diff) | |
download | dexon-2a9fc7baa908d64ff1ddae44641024114d3ec88d.tar.gz dexon-2a9fc7baa908d64ff1ddae44641024114d3ec88d.tar.zst dexon-2a9fc7baa908d64ff1ddae44641024114d3ec88d.zip |
Merge branch 'develop' of https://github.com/tgerring/go-ethereum
Diffstat (limited to 'ethutil/value_test.go')
-rw-r--r-- | ethutil/value_test.go | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/ethutil/value_test.go b/ethutil/value_test.go index 5452a0790..7c58d3b56 100644 --- a/ethutil/value_test.go +++ b/ethutil/value_test.go @@ -1,86 +1,69 @@ package ethutil import ( - "bytes" - "fmt" + checker "gopkg.in/check.v1" "math/big" - "testing" ) -func TestValueCmp(t *testing.T) { +type ValueSuite struct{} + +var _ = checker.Suite(&ValueSuite{}) + +func (s *ValueSuite) TestValueCmp(c *checker.C) { val1 := NewValue("hello") val2 := NewValue("world") - if val1.Cmp(val2) { - t.Error("Expected values not to be equal") - } + c.Assert(val1.Cmp(val2), checker.Equals, false) val3 := NewValue("hello") val4 := NewValue("hello") - if !val3.Cmp(val4) { - t.Error("Expected values to be equal") - } + c.Assert(val3.Cmp(val4), checker.Equals, true) } -func TestValueTypes(t *testing.T) { +func (s *ValueSuite) TestValueTypes(c *checker.C) { str := NewValue("str") num := NewValue(1) inter := NewValue([]interface{}{1}) byt := NewValue([]byte{1, 2, 3, 4}) bigInt := NewValue(big.NewInt(10)) - if str.Str() != "str" { - t.Errorf("expected Str to return 'str', got %s", str.Str()) - } - - if num.Uint() != 1 { - t.Errorf("expected Uint to return '1', got %d", num.Uint()) - } - + strExp := "str" + numExp := uint64(1) interExp := []interface{}{1} - if !NewValue(inter.Interface()).Cmp(NewValue(interExp)) { - t.Errorf("expected Interface to return '%v', got %v", interExp, num.Interface()) - } - bytExp := []byte{1, 2, 3, 4} - if bytes.Compare(byt.Bytes(), bytExp) != 0 { - t.Errorf("expected Bytes to return '%v', got %v", bytExp, byt.Bytes()) - } - bigExp := big.NewInt(10) - if bigInt.BigInt().Cmp(bigExp) != 0 { - t.Errorf("expected BigInt to return '%v', got %v", bigExp, bigInt.BigInt()) - } + + c.Assert(str.Str(), checker.Equals, strExp) + c.Assert(num.Uint(), checker.Equals, numExp) + c.Assert(NewValue(inter.Interface()).Cmp(NewValue(interExp)), checker.Equals, true) + c.Assert(byt.Bytes(), checker.DeepEquals, bytExp) + c.Assert(bigInt.BigInt(), checker.DeepEquals, bigExp) } -func TestIterator(t *testing.T) { +func (s *ValueSuite) TestIterator(c *checker.C) { value := NewValue([]interface{}{1, 2, 3}) - it := value.NewIterator() + iter := value.NewIterator() values := []uint64{1, 2, 3} i := 0 - for it.Next() { - if values[i] != it.Value().Uint() { - t.Errorf("Expected %d, got %d", values[i], it.Value().Uint()) - } + for iter.Next() { + c.Assert(values[i], checker.Equals, iter.Value().Uint()) i++ } } -func TestMath(t *testing.T) { - a := NewValue(1) - a.Add(1).Add(1) - - if !a.DeepCmp(NewValue(3)) { - t.Error("Expected 3, got", a) - } +func (s *ValueSuite) TestMath(c *checker.C) { + data1 := NewValue(1) + data1.Add(1).Add(1) + exp1 := NewValue(3) + data2 := NewValue(2) + data2.Sub(1).Sub(1) + exp2 := NewValue(0) - a = NewValue(2) - a.Sub(1).Sub(1) - if !a.DeepCmp(NewValue(0)) { - t.Error("Expected 0, got", a) - } + c.Assert(data1.DeepCmp(exp1), checker.Equals, true) + c.Assert(data2.DeepCmp(exp2), checker.Equals, true) } -func TestString(t *testing.T) { - a := NewValue("10") - fmt.Println("VALUE WITH STRING:", a.Int()) +func (s *ValueSuite) TestString(c *checker.C) { + data := "10" + exp := int64(10) + c.Assert(NewValue(data).Int(), checker.DeepEquals, exp) } |