github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/rand/rand_test.gno (about) 1 package rand 2 3 import ( 4 "fmt" 5 "std" 6 "strings" 7 "testing" 8 9 "gno.land/p/demo/rand" 10 ) 11 12 func TestInstance(t *testing.T) { 13 instance := rand.New() 14 if instance == nil { 15 t.Errorf("instance should not be nil") 16 } 17 } 18 19 func TestIntn(t *testing.T) { 20 baseRand := rand.New() 21 baseResult := computeIntn(t, baseRand) 22 23 sameHeightRand := rand.New() 24 sameHeightResult := computeIntn(t, sameHeightRand) 25 26 if baseResult != sameHeightResult { 27 t.Errorf("should have the same result: new=%s, base=%s", sameHeightResult, baseResult) 28 } 29 30 std.TestSkipHeights(1) 31 differentHeightRand := rand.New() 32 differentHeightResult := computeIntn(t, differentHeightRand) 33 34 if baseResult == differentHeightResult { 35 t.Errorf("should have different result: new=%s, base=%s", differentHeightResult, baseResult) 36 } 37 } 38 39 func computeIntn(t *testing.T, r *rand.Instance) string { 40 t.Helper() 41 42 arr := []string{} 43 for i := 0; i < 10; i++ { 44 arr = append(arr, fmt.Sprintf("%d", r.Intn(1000))) 45 } 46 47 out := strings.Join(arr, ",") 48 return out 49 }