Convert value_test to use gocheck
This commit is contained in:
parent
3c619baec5
commit
cd94b5ffb3
|
@ -1,89 +1,72 @@
|
||||||
package ethutil
|
package ethutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
checker "gopkg.in/check.v1"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValueCmp(t *testing.T) {
|
func Test(t *testing.T) { checker.TestingT(t) }
|
||||||
|
|
||||||
|
type ValueSuite struct{}
|
||||||
|
|
||||||
|
var _ = checker.Suite(&ValueSuite{})
|
||||||
|
|
||||||
|
func (s *ValueSuite) TestValueCmp(c *checker.C) {
|
||||||
val1 := NewValue("hello")
|
val1 := NewValue("hello")
|
||||||
val2 := NewValue("world")
|
val2 := NewValue("world")
|
||||||
if val1.Cmp(val2) {
|
c.Assert(val1.Cmp(val2), checker.Equals, false)
|
||||||
t.Error("Expected values not to be equal")
|
|
||||||
}
|
|
||||||
|
|
||||||
val3 := NewValue("hello")
|
val3 := NewValue("hello")
|
||||||
val4 := NewValue("hello")
|
val4 := NewValue("hello")
|
||||||
if !val3.Cmp(val4) {
|
c.Assert(val3.Cmp(val4), checker.Equals, true)
|
||||||
t.Error("Expected values to be equal")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValueTypes(t *testing.T) {
|
func (s *ValueSuite) TestValueTypes(c *checker.C) {
|
||||||
str := NewValue("str")
|
str := NewValue("str")
|
||||||
num := NewValue(1)
|
num := NewValue(1)
|
||||||
inter := NewValue([]interface{}{1})
|
inter := NewValue([]interface{}{1})
|
||||||
byt := NewValue([]byte{1, 2, 3, 4})
|
byt := NewValue([]byte{1, 2, 3, 4})
|
||||||
bigInt := NewValue(big.NewInt(10))
|
bigInt := NewValue(big.NewInt(10))
|
||||||
|
|
||||||
if str.Str() != "str" {
|
strExp := "str"
|
||||||
t.Errorf("expected Str to return 'str', got %s", str.Str())
|
numExp := uint64(1)
|
||||||
}
|
|
||||||
|
|
||||||
if num.Uint() != 1 {
|
|
||||||
t.Errorf("expected Uint to return '1', got %d", num.Uint())
|
|
||||||
}
|
|
||||||
|
|
||||||
interExp := []interface{}{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}
|
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)
|
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})
|
value := NewValue([]interface{}{1, 2, 3})
|
||||||
it := value.NewIterator()
|
iter := value.NewIterator()
|
||||||
values := []uint64{1, 2, 3}
|
values := []uint64{1, 2, 3}
|
||||||
i := 0
|
i := 0
|
||||||
for it.Next() {
|
for iter.Next() {
|
||||||
if values[i] != it.Value().Uint() {
|
c.Assert(values[i], checker.Equals, iter.Value().Uint())
|
||||||
t.Errorf("Expected %d, got %d", values[i], it.Value().Uint())
|
|
||||||
}
|
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMath(t *testing.T) {
|
func (s *ValueSuite) TestMath(c *checker.C) {
|
||||||
a := NewValue(1)
|
data1 := NewValue(1)
|
||||||
a.Add(1).Add(1)
|
data1.Add(1).Add(1)
|
||||||
|
exp1 := NewValue(3)
|
||||||
|
data2 := NewValue(2)
|
||||||
|
data2.Sub(1).Sub(1)
|
||||||
|
exp2 := NewValue(0)
|
||||||
|
|
||||||
if !a.DeepCmp(NewValue(3)) {
|
c.Assert(data1.DeepCmp(exp1), checker.Equals, true)
|
||||||
t.Error("Expected 3, got", a)
|
c.Assert(data2.DeepCmp(exp2), checker.Equals, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
a = NewValue(2)
|
func (s *ValueSuite) TestString(c *checker.C) {
|
||||||
a.Sub(1).Sub(1)
|
|
||||||
if !a.DeepCmp(NewValue(0)) {
|
|
||||||
t.Error("Expected 0, got", a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
|
||||||
data := "10"
|
data := "10"
|
||||||
exp := int64(10)
|
exp := int64(10)
|
||||||
res := NewValue(data).Int()
|
c.Assert(NewValue(data).Int(), checker.DeepEquals, exp)
|
||||||
if res != exp {
|
|
||||||
t.Errorf("Exprected %d Got res", exp, res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue