big_test.go 1.1 KB

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