github.com/karalabe/go-ethereum@v0.8.5/ethutil/common_test.go (about)

     1  package ethutil
     2  
     3  import (
     4  	"math/big"
     5  	"os"
     6  
     7  	checker "gopkg.in/check.v1"
     8  )
     9  
    10  type CommonSuite struct{}
    11  
    12  var _ = checker.Suite(&CommonSuite{})
    13  
    14  func (s *CommonSuite) TestOS(c *checker.C) {
    15  	expwin := (os.PathSeparator == '\\' && os.PathListSeparator == ';')
    16  	res := IsWindows()
    17  
    18  	if !expwin {
    19  		c.Assert(res, checker.Equals, expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
    20  	} else {
    21  		c.Assert(res, checker.Not(checker.Equals), expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
    22  	}
    23  }
    24  
    25  func (s *CommonSuite) TestWindonziePath(c *checker.C) {
    26  	iswindowspath := os.PathSeparator == '\\'
    27  	path := "/opt/eth/test/file.ext"
    28  	res := WindonizePath(path)
    29  	ressep := string(res[0])
    30  
    31  	if !iswindowspath {
    32  		c.Assert(ressep, checker.Equals, "/")
    33  	} else {
    34  		c.Assert(ressep, checker.Not(checker.Equals), "/")
    35  	}
    36  }
    37  
    38  func (s *CommonSuite) TestCommon(c *checker.C) {
    39  	douglas := CurrencyToString(BigPow(10, 43))
    40  	einstein := CurrencyToString(BigPow(10, 22))
    41  	ether := CurrencyToString(BigPow(10, 19))
    42  	finney := CurrencyToString(BigPow(10, 16))
    43  	szabo := CurrencyToString(BigPow(10, 13))
    44  	shannon := CurrencyToString(BigPow(10, 10))
    45  	babbage := CurrencyToString(BigPow(10, 7))
    46  	ada := CurrencyToString(BigPow(10, 4))
    47  	wei := CurrencyToString(big.NewInt(10))
    48  
    49  	c.Assert(douglas, checker.Equals, "10 Douglas")
    50  	c.Assert(einstein, checker.Equals, "10 Einstein")
    51  	c.Assert(ether, checker.Equals, "10 Ether")
    52  	c.Assert(finney, checker.Equals, "10 Finney")
    53  	c.Assert(szabo, checker.Equals, "10 Szabo")
    54  	c.Assert(shannon, checker.Equals, "10 Shannon")
    55  	c.Assert(babbage, checker.Equals, "10 Babbage")
    56  	c.Assert(ada, checker.Equals, "10 Ada")
    57  	c.Assert(wei, checker.Equals, "10 Wei")
    58  }
    59  
    60  func (s *CommonSuite) TestLarge(c *checker.C) {
    61  	douglaslarge := CurrencyToString(BigPow(100000000, 43))
    62  	adalarge := CurrencyToString(BigPow(100000000, 4))
    63  	weilarge := CurrencyToString(big.NewInt(100000000))
    64  
    65  	c.Assert(douglaslarge, checker.Equals, "10000E298 Douglas")
    66  	c.Assert(adalarge, checker.Equals, "10000E7 Einstein")
    67  	c.Assert(weilarge, checker.Equals, "100 Babbage")
    68  }