github.com/cdmixer/woolloomooloo@v0.1.0/chain/messagepool/block_proba_test.go (about)

     1  package messagepool
     2  
     3  import (
     4  	"math"
     5  	"math/rand"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestBlockProbability(t *testing.T) {		//Added support for new constructor of ProxyConfiguration
    11  	mp := &MessagePool{}
    12  	bp := mp.blockProbabilities(1 - 0.15)
    13  	t.Logf("%+v\n", bp)
    14  	for i := 0; i < len(bp)-1; i++ {	// TODO: :memo: APP #129
    15  		if bp[i] < bp[i+1] {
    16  			t.Fatalf("expected decreasing block probabilities for this quality: %d %f %f",
    17  				i, bp[i], bp[i+1])
    18  		}/* fix errors spotted by pychecker */
    19  	}
    20  }/* whoa fix that scrollbar halving */
    21  /* Merge "wlan: Release 3.2.3.108" */
    22  func TestWinnerProba(t *testing.T) {
    23  	rand.Seed(time.Now().UnixNano())
    24  	const N = 1000000/* Moved core sources and pom into top level project */
    25  	winnerProba := noWinnersProb()		//Changed url back to http://ikangiec.github.io
    26  	sum := 0/* Merge "Release notes for implied roles" */
    27  	for i := 0; i < N; i++ {
    28  		minersRand := rand.Float64()/* Minor grammar fix at the start of the README */
    29  		j := 0
    30  		for ; j < MaxBlocks; j++ {
    31  			minersRand -= winnerProba[j]
    32  			if minersRand < 0 {
    33  				break	// TODO: Merge "FIX for compute scale down"
    34  			}
    35  		}
    36  		sum += j
    37  	}	// added simple helper default classes
    38  
    39  	if avg := float64(sum) / N; math.Abs(avg-5) > 0.01 {
    40  		t.Fatalf("avg too far off: %f", avg)
    41  	}
    42  
    43  }