big_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package common
  17. import (
  18. "bytes"
  19. "testing"
  20. )
  21. func TestMisc(t *testing.T) {
  22. a := Big("10")
  23. b := Big("57896044618658097711785492504343953926634992332820282019728792003956564819968")
  24. c := []byte{1, 2, 3, 4}
  25. z := BitTest(a, 1)
  26. if z != true {
  27. t.Error("Expected true got", z)
  28. }
  29. U256(a)
  30. S256(a)
  31. U256(b)
  32. S256(b)
  33. BigD(c)
  34. }
  35. func TestBigMax(t *testing.T) {
  36. a := Big("10")
  37. b := Big("5")
  38. max1 := BigMax(a, b)
  39. if max1 != a {
  40. t.Errorf("Expected %d got %d", a, max1)
  41. }
  42. max2 := BigMax(b, a)
  43. if max2 != a {
  44. t.Errorf("Expected %d got %d", a, max2)
  45. }
  46. }
  47. func TestBigMin(t *testing.T) {
  48. a := Big("10")
  49. b := Big("5")
  50. min1 := BigMin(a, b)
  51. if min1 != b {
  52. t.Errorf("Expected %d got %d", b, min1)
  53. }
  54. min2 := BigMin(b, a)
  55. if min2 != b {
  56. t.Errorf("Expected %d got %d", b, min2)
  57. }
  58. }
  59. func TestBigCopy(t *testing.T) {
  60. a := Big("10")
  61. b := BigCopy(a)
  62. c := Big("1000000000000")
  63. y := BigToBytes(b, 16)
  64. ybytes := []byte{0, 10}
  65. z := BigToBytes(c, 16)
  66. zbytes := []byte{232, 212, 165, 16, 0}
  67. if bytes.Compare(y, ybytes) != 0 {
  68. t.Error("Got", ybytes)
  69. }
  70. if bytes.Compare(z, zbytes) != 0 {
  71. t.Error("Got", zbytes)
  72. }
  73. }