size_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "math/big"
  19. checker "gopkg.in/check.v1"
  20. )
  21. type SizeSuite struct{}
  22. var _ = checker.Suite(&SizeSuite{})
  23. func (s *SizeSuite) TestStorageSizeString(c *checker.C) {
  24. data1 := 2381273
  25. data2 := 2192
  26. data3 := 12
  27. exp1 := "2.38 mB"
  28. exp2 := "2.19 kB"
  29. exp3 := "12.00 B"
  30. c.Assert(StorageSize(data1).String(), checker.Equals, exp1)
  31. c.Assert(StorageSize(data2).String(), checker.Equals, exp2)
  32. c.Assert(StorageSize(data3).String(), checker.Equals, exp3)
  33. }
  34. func (s *CommonSuite) TestCommon(c *checker.C) {
  35. ether := CurrencyToString(BigPow(10, 19))
  36. finney := CurrencyToString(BigPow(10, 16))
  37. szabo := CurrencyToString(BigPow(10, 13))
  38. shannon := CurrencyToString(BigPow(10, 10))
  39. babbage := CurrencyToString(BigPow(10, 7))
  40. ada := CurrencyToString(BigPow(10, 4))
  41. wei := CurrencyToString(big.NewInt(10))
  42. c.Assert(ether, checker.Equals, "10 Ether")
  43. c.Assert(finney, checker.Equals, "10 Finney")
  44. c.Assert(szabo, checker.Equals, "10 Szabo")
  45. c.Assert(shannon, checker.Equals, "10 Shannon")
  46. c.Assert(babbage, checker.Equals, "10 Babbage")
  47. c.Assert(ada, checker.Equals, "10 Ada")
  48. c.Assert(wei, checker.Equals, "10 Wei")
  49. }