github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/storelaw/vote_state_law_test.go (about) 1 package storelaw 2 3 import ( 4 "fmt" 5 "math/big" 6 "runtime" 7 "testing" 8 ) 9 10 func TestVoteState_GetResult(t *testing.T) { 11 vs := &VoteState{ 12 Agree: big.NewInt(660), 13 Against: big.NewInt(220), 14 Abstention: big.NewInt(100), 15 } 16 vs1 := &VoteState{ 17 Agree: big.NewInt(671), 18 Against: big.NewInt(100), 19 Abstention: big.NewInt(100), 20 } 21 22 total := big.NewInt(1000) 23 proportion := int64(67) 24 25 fmt.Println(vs.GetResult(total, proportion)) 26 fmt.Println(vs1.GetResult(total, proportion)) 27 } 28 29 func TestMap(t *testing.T) { 30 m := make(map[int]bool) 31 for i := 0; i < 1e8; i++ { 32 m[i] = true 33 delete(m, i) 34 if i%100 == 0 { 35 printMemStats() 36 } 37 } 38 } 39 func printMemStats() { 40 var m runtime.MemStats 41 runtime.ReadMemStats(&m) 42 fmt.Printf("HeapAlloc = %v HeapIdel= %v HeapSys = %v HeapReleased = %v\n", m.HeapAlloc/1024, m.HeapIdle/1024, m.HeapSys/1024, m.HeapReleased/1024) 43 }