11package mathx
22
3- import "testing"
3+ import (
4+ "math/rand"
5+ "testing"
6+ )
47
58const seed = 1658340109320624211
69
7- func TestRandom_GetRandomInt (t * testing.T ) {
10+ func TestGetRandomInt (t * testing.T ) {
811 tests := []struct {
912 name string
1013 max int
@@ -32,14 +35,14 @@ func TestRandom_GetRandomInt(t *testing.T) {
3235 }
3336 for _ , tt := range tests {
3437 t .Run (tt .name , func (t * testing.T ) {
35- r := NewRandom (seed )
36- got := r . GetRandomInt (tt .max )
38+ rand . Seed (seed )
39+ got := GetRandomInt (tt .max )
3740
3841 if got != tt .expected1 {
3942 t .Errorf ("GetRandomInt() = %d, want %d" , got , tt .expected1 )
4043 }
4144
42- got = r . GetRandomInt (tt .max )
45+ got = GetRandomInt (tt .max )
4346
4447 if got != tt .expected2 {
4548 t .Errorf ("GetRandomInt() = %d, want %d" , got , tt .expected2 )
@@ -48,7 +51,7 @@ func TestRandom_GetRandomInt(t *testing.T) {
4851 }
4952}
5053
51- func TestRandom_GetExpDistributedInt (t * testing.T ) {
54+ func TestGetExpDistributedInt (t * testing.T ) {
5255 tests := []struct {
5356 name string
5457 rate float64
@@ -76,14 +79,14 @@ func TestRandom_GetExpDistributedInt(t *testing.T) {
7679 }
7780 for _ , tt := range tests {
7881 t .Run (tt .name , func (t * testing.T ) {
79- r := NewRandom (seed )
80- got := r . GetExpDistributedInt (tt .rate )
82+ rand . Seed (seed )
83+ got := GetExpDistributedInt (tt .rate )
8184
8285 if got != tt .expected1 {
8386 t .Errorf ("GetExpDistributedInt() = %d, want %d" , got , tt .expected1 )
8487 }
8588
86- got = r . GetExpDistributedInt (tt .rate )
89+ got = GetExpDistributedInt (tt .rate )
8790
8891 if got != tt .expected2 {
8992 t .Errorf ("GetExpDistributedInt() = %d, want %d" , got , tt .expected2 )
0 commit comments