github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/common/size_test.go (about) 1 // Copyright 2014 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library 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 // The go-ethereum library 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 the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package common 18 19 import ( 20 "math/big" 21 22 checker "gopkg.in/check.v1" 23 ) 24 25 type SizeSuite struct{} 26 27 var _ = checker.Suite(&SizeSuite{}) 28 29 func (s *SizeSuite) TestStorageSizeString(c *checker.C) { 30 data1 := 2381273 31 data2 := 2192 32 data3 := 12 33 34 exp1 := "2.38 mB" 35 exp2 := "2.19 kB" 36 exp3 := "12.00 B" 37 38 c.Assert(StorageSize(data1).String(), checker.Equals, exp1) 39 c.Assert(StorageSize(data2).String(), checker.Equals, exp2) 40 c.Assert(StorageSize(data3).String(), checker.Equals, exp3) 41 } 42 43 func (s *SizeSuite) TestCommon(c *checker.C) { 44 ether := CurrencyToString(BigPow(10, 19)) 45 finney := CurrencyToString(BigPow(10, 16)) 46 szabo := CurrencyToString(BigPow(10, 13)) 47 shannon := CurrencyToString(BigPow(10, 10)) 48 babbage := CurrencyToString(BigPow(10, 7)) 49 ada := CurrencyToString(BigPow(10, 4)) 50 wei := CurrencyToString(big.NewInt(10)) 51 52 c.Assert(ether, checker.Equals, "10 Ether") 53 c.Assert(finney, checker.Equals, "10 Finney") 54 c.Assert(szabo, checker.Equals, "10 Szabo") 55 c.Assert(shannon, checker.Equals, "10 Shannon") 56 c.Assert(babbage, checker.Equals, "10 Babbage") 57 c.Assert(ada, checker.Equals, "10 Ada") 58 c.Assert(wei, checker.Equals, "10 Wei") 59 }