github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/chief/service_test.go (about)

     1  package chief
     2  
     3  import (
     4  	"math/big"
     5  	"testing"
     6  )
     7  
     8  func TestA(t *testing.T) {
     9  	var (
    10  		fn func(_vrfn *big.Int) int
    11  		nl = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
    12  		//vl = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
    13  		vl = []int{2, 4, 6, 8}
    14  	)
    15  
    16  	for i := 10; i < 20; i++ {
    17  		vrfn := big.NewInt(int64(i))
    18  		fn = func(_vrfn *big.Int) int {
    19  			m := big.NewInt(int64(len(nl)))
    20  			x := new(big.Int).Sub(_vrfn, vrfn)
    21  			if x.Cmp(m) >= 0 {
    22  				return 0
    23  			}
    24  			idx := new(big.Int).Mod(_vrfn, m)
    25  			// skip if `n` in volunteer list
    26  			v := nl[idx.Int64()]
    27  			for _, vol := range vl {
    28  				if vol == v {
    29  					return fn(new(big.Int).Add(_vrfn, big.NewInt(1)))
    30  				}
    31  			}
    32  			return v
    33  		}
    34  		r := fn(vrfn)
    35  		t.Log(vrfn, "-->", r)
    36  	}
    37  }