v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/fastrand/u64_test.go (about)

     1  package fastrand
     2  
     3  import "testing"
     4  
     5  func TestRNG_Int63(t *testing.T) {
     6  	t.Run("isNegative", func(t *testing.T) {
     7  		rng := AcquireRNG()
     8  		defer ReleaseRNG(rng)
     9  		for i := 0; i < 100000; i++ {
    10  			if rng.Int63() < 0 {
    11  				t.Errorf("rng.Int63() < 0")
    12  			}
    13  		}
    14  	})
    15  }
    16  
    17  func Test_Int63n(t *testing.T) {
    18  	rng := AcquireRNG()
    19  	defer ReleaseRNG(rng)
    20  	rng.SetSeed(42)
    21  	for i := 0; i < 100000; i++ {
    22  		if rng.Int63n(10) < 0 {
    23  			t.Errorf("rng.Int63n(10) < 0")
    24  		}
    25  		if rng.Int63n(100) < 0 {
    26  			t.Errorf("rng.Int63n(100) < 0")
    27  		}
    28  	}
    29  }
    30  
    31  func BenchmarkRNGUint64(b *testing.B) {
    32  	b.RunParallel(func(p *testing.PB) {
    33  		rng := AcquireRNG()
    34  		for p.Next() {
    35  			_ = rng.Uint64()
    36  		}
    37  		ReleaseRNG(rng)
    38  	})
    39  }
    40  
    41  func BenchmarkRNGUint64n(b *testing.B) {
    42  	b.RunParallel(func(p *testing.PB) {
    43  		rng := AcquireRNG()
    44  		for p.Next() {
    45  			_ = rng.Uint64n(1)
    46  		}
    47  		ReleaseRNG(rng)
    48  	})
    49  }
    50  
    51  func BenchmarkRNGInt63(b *testing.B) {
    52  	b.RunParallel(func(p *testing.PB) {
    53  		rng := AcquireRNG()
    54  		for p.Next() {
    55  			_ = rng.Int63()
    56  		}
    57  		ReleaseRNG(rng)
    58  	})
    59  }
    60  
    61  func BenchmarkRNGInt63n(b *testing.B) {
    62  	b.RunParallel(func(p *testing.PB) {
    63  		rng := AcquireRNG()
    64  		for p.Next() {
    65  			_ = rng.Int63n(1)
    66  		}
    67  		ReleaseRNG(rng)
    68  	})
    69  }
    70  
    71  func BenchmarkRNGInt64(b *testing.B) {
    72  	b.RunParallel(func(p *testing.PB) {
    73  		rng := AcquireRNG()
    74  		for p.Next() {
    75  			_ = rng.Int64()
    76  		}
    77  		ReleaseRNG(rng)
    78  	})
    79  }
    80  
    81  func BenchmarkUint64(b *testing.B) {
    82  	b.RunParallel(func(p *testing.PB) {
    83  		for p.Next() {
    84  			_ = Uint64()
    85  		}
    86  	})
    87  }
    88  
    89  func BenchmarkUint64n(b *testing.B) {
    90  	b.RunParallel(func(p *testing.PB) {
    91  		for p.Next() {
    92  			_ = Uint64n(100)
    93  		}
    94  	})
    95  }