github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/common/math/dist_test.go (about) 1 // Copyright 2015 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 math 18 19 import ( 20 "fmt" 21 "math/big" 22 "testing" 23 ) 24 25 type summer struct { 26 numbers []*big.Int 27 } 28 29 func (s summer) Len() int { return len(s.numbers) } 30 func (s summer) Sum(i int) *big.Int { 31 return s.numbers[i] 32 } 33 34 func TestSum(t *testing.T) { 35 summer := summer{numbers: []*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)}} 36 sum := Sum(summer) 37 if sum.Cmp(big.NewInt(6)) != 0 { 38 t.Errorf("got sum = %d, want 6", sum) 39 } 40 } 41 42 func TestDist(t *testing.T) { 43 var vectors = []Vector{ 44 {big.NewInt(1000), big.NewInt(1234)}, 45 {big.NewInt(500), big.NewInt(10023)}, 46 {big.NewInt(1034), big.NewInt(1987)}, 47 {big.NewInt(1034), big.NewInt(1987)}, 48 {big.NewInt(8983), big.NewInt(1977)}, 49 {big.NewInt(98382), big.NewInt(1887)}, 50 {big.NewInt(12398), big.NewInt(1287)}, 51 {big.NewInt(12398), big.NewInt(1487)}, 52 {big.NewInt(12398), big.NewInt(1987)}, 53 {big.NewInt(12398), big.NewInt(128)}, 54 {big.NewInt(12398), big.NewInt(1987)}, 55 {big.NewInt(1398), big.NewInt(187)}, 56 {big.NewInt(12328), big.NewInt(1927)}, 57 {big.NewInt(12398), big.NewInt(1987)}, 58 {big.NewInt(22398), big.NewInt(1287)}, 59 {big.NewInt(1370), big.NewInt(1981)}, 60 {big.NewInt(12398), big.NewInt(1957)}, 61 {big.NewInt(42198), big.NewInt(1987)}, 62 } 63 64 VectorsBy(GasSort).Sort(vectors) 65 fmt.Println(vectors) 66 67 BP := big.NewInt(15) 68 GL := big.NewInt(1000000) 69 EP := big.NewInt(100) 70 fmt.Println("BP", BP, "GL", GL, "EP", EP) 71 GP := GasPrice(BP, GL, EP) 72 fmt.Println("GP =", GP, "Wei per GU") 73 74 S := len(vectors) / 4 75 fmt.Println("L", len(vectors), "S", S) 76 for i := 1; i <= S*4; i += S { 77 fmt.Printf("T%d = %v\n", i, vectors[i]) 78 } 79 80 g := VectorSum(GasSum).Sum(vectors) 81 fmt.Printf("G = ∑g* (%v)\n", g) 82 }