aboutsummaryrefslogtreecommitdiffstats
path: root/common/value_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-16 18:27:38 +0800
committerobscuren <geffobscura@gmail.com>2015-03-16 18:27:38 +0800
commitb5234413611ce5984292f85a01de1f56c045b490 (patch)
treee6e0c6f7fe8358a2dc63cdea11ac66b4f59397f5 /common/value_test.go
parent0b8f66ed9ef177dc72442dd7ba337c6733e30344 (diff)
downloaddexon-b5234413611ce5984292f85a01de1f56c045b490.tar
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.gz
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.bz2
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.lz
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.xz
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.zst
dexon-b5234413611ce5984292f85a01de1f56c045b490.zip
Moved ethutil => common
Diffstat (limited to 'common/value_test.go')
-rw-r--r--common/value_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/common/value_test.go b/common/value_test.go
new file mode 100644
index 000000000..09d37802d
--- /dev/null
+++ b/common/value_test.go
@@ -0,0 +1,70 @@
+package common
+
+import (
+ "math/big"
+
+ checker "gopkg.in/check.v1"
+)
+
+type ValueSuite struct{}
+
+var _ = checker.Suite(&ValueSuite{})
+
+func (s *ValueSuite) TestValueCmp(c *checker.C) {
+ val1 := NewValue("hello")
+ val2 := NewValue("world")
+ c.Assert(val1.Cmp(val2), checker.Equals, false)
+
+ val3 := NewValue("hello")
+ val4 := NewValue("hello")
+ c.Assert(val3.Cmp(val4), checker.Equals, true)
+}
+
+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))
+
+ strExp := "str"
+ numExp := uint64(1)
+ interExp := []interface{}{1}
+ bytExp := []byte{1, 2, 3, 4}
+ bigExp := big.NewInt(10)
+
+ 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 (s *ValueSuite) TestIterator(c *checker.C) {
+ value := NewValue([]interface{}{1, 2, 3})
+ iter := value.NewIterator()
+ values := []uint64{1, 2, 3}
+ i := 0
+ for iter.Next() {
+ c.Assert(values[i], checker.Equals, iter.Value().Uint())
+ i++
+ }
+}
+
+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)
+
+ c.Assert(data1.DeepCmp(exp1), checker.Equals, true)
+ c.Assert(data2.DeepCmp(exp2), checker.Equals, true)
+}
+
+func (s *ValueSuite) TestString(c *checker.C) {
+ data := "10"
+ exp := int64(10)
+ c.Assert(NewValue(data).Int(), checker.DeepEquals, exp)
+}