github.com/CAFxX/fastrand@v0.1.0/splitmix64_test.go (about)

     1  package fastrand
     2  
     3  import "testing"
     4  
     5  var expSplitMix64 = []uint64{0x910a2dec89025cc1, 0xbeeb8da1658eec67, 0xf893a2eefb32555e, 0x71c18690ee42c90b, 0x71bb54d8d101b5b9, 0xc34d0bff90150280, 0xe099ec6cd7363ca5, 0x85e7bb0f12278575}
     6  
     7  func TestSplitMix64(t *testing.T) {
     8  	var r SplitMix64
     9  	r.Seed(1)
    10  	for i, e := range expSplitMix64 {
    11  		if g := r.Uint64(); g != e {
    12  			t.Errorf("i=%d, expected=%x, got=%x", i, e, g)
    13  		}
    14  	}
    15  }
    16  
    17  func TestAtomicSplitMix64(t *testing.T) {
    18  	var r AtomicSplitMix64
    19  	r.Seed(1)
    20  	for i, e := range expSplitMix64 {
    21  		if g := r.Uint64(); g != e {
    22  			t.Errorf("i=%d, expected=%x, got=%x", i, e, g)
    23  		}
    24  	}
    25  }
    26  
    27  func TestShardedSplitMix64Fallback(t *testing.T) {
    28  	var r ShardedSplitMix64 // no shards created
    29  	r.fallback.Seed(1)
    30  	for i, e := range expSplitMix64 {
    31  		if g := r.Uint64(); g != e {
    32  			t.Errorf("i=%d, expected=%x, got=%x", i, e, g)
    33  		}
    34  	}
    35  }
    36  
    37  func TestShardedSplitMix64(t *testing.T) {
    38  	r := NewShardedSplitMix64()
    39  	id := procPin()
    40  	defer procUnpin()
    41  	if fastrand_nounsafe {
    42  		r.fallback.Seed(1)
    43  	} else {
    44  		r.states[id].Seed(1)
    45  	}
    46  	for i, e := range expSplitMix64 {
    47  		if g := r.Uint64(); g != e {
    48  			t.Errorf("i=%d, expected=%x, got=%x", i, e, g)
    49  		}
    50  	}
    51  }