github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/siac/parse_test.go (about) 1 package main 2 3 import ( 4 "math/big" 5 "testing" 6 7 "github.com/NebulousLabs/Sia/types" 8 ) 9 10 func TestParseFilesize(t *testing.T) { 11 tests := []struct { 12 in, out string 13 err error 14 }{ 15 {"1b", "1", nil}, 16 {"1KB", "1000", nil}, 17 {"1MB", "1000000", nil}, 18 {"1GB", "1000000000", nil}, 19 {"1TB", "1000000000000", nil}, 20 {"1KiB", "1024", nil}, 21 {"1MiB", "1048576", nil}, 22 {"1GiB", "1073741824", nil}, 23 {"1TiB", "1099511627776", nil}, 24 {"", "", errUnableToParseSize}, 25 {"123", "123", nil}, 26 {"123TB", "123000000000000", nil}, 27 {"123GiB", "132070244352", nil}, 28 {"123BiB", "", errUnableToParseSize}, 29 {"GB", "", errUnableToParseSize}, 30 {"123G", "", errUnableToParseSize}, 31 {"123B99", "", errUnableToParseSize}, 32 {"12A3456", "", errUnableToParseSize}, 33 {"1.23KB", "1230", nil}, 34 {"1.234KB", "1234", nil}, 35 {"1.2345KB", "1234", nil}, 36 } 37 for _, test := range tests { 38 res, err := parseFilesize(test.in) 39 if res != test.out || err != test.err { 40 t.Errorf("parseFilesize(%v): expected %v %v, got %v %v", test.in, test.out, test.err, res, err) 41 } 42 } 43 } 44 45 func TestCurrencyUnits(t *testing.T) { 46 tests := []struct { 47 in, out string 48 }{ 49 {"1", "1 H"}, 50 {"1000", "1000 H"}, 51 {"100000000000", "100000000000 H"}, 52 {"1000000000000", "1 pS"}, 53 {"1234560000000", "1.235 pS"}, 54 {"12345600000000", "12.35 pS"}, 55 {"123456000000000", "123.5 pS"}, 56 {"1000000000000000", "1 nS"}, 57 {"1000000000000000000", "1 uS"}, 58 {"1000000000000000000000", "1 mS"}, 59 {"1000000000000000000000000", "1 SC"}, 60 {"1000000000000000000000000000", "1 KS"}, 61 {"1000000000000000000000000000000", "1 MS"}, 62 {"1000000000000000000000000000000000", "1 GS"}, 63 {"1000000000000000000000000000000000000", "1 TS"}, 64 {"1234560000000000000000000000000000000", "1.235 TS"}, 65 {"1234560000000000000000000000000000000000", "1235 TS"}, 66 } 67 for _, test := range tests { 68 i, _ := new(big.Int).SetString(test.in, 10) 69 out := currencyUnits(types.NewCurrency(i)) 70 if out != test.out { 71 t.Errorf("currencyUnits(%v): expected %v, got %v", test.in, test.out, out) 72 } 73 } 74 }