123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package utils_test
-
- import (
- "spaceofcheng/services/utils"
- "testing"
- )
-
- func TestGetRand(t *testing.T) {
- res1 := utils.GetRand(6)
- res2 := utils.GetRand(6)
-
- if res1 == res2 {
- t.Fatalf("TestGetRand error, %s, %s", res1, res2)
- }
- }
-
- func TestLuckyDraw(t *testing.T) {
- prizeList := []map[string]interface{}{
- map[string]interface{}{
- "prize": "A",
- "prob": 20,
- },
- map[string]interface{}{
- "prize": "B",
- "prob": 20,
- },
- map[string]interface{}{
- "prize": "C",
- "prob": 30,
- },
- map[string]interface{}{
- "prize": "D",
- "prob": 30,
- },
- }
-
- theA := 0
- theB := 0
- theC := 0
- theD := 0
-
- for i := 0; i < 10000; i++ {
- res := utils.LuckyDraw(prizeList).(string)
-
- switch res {
- case "A":
- theA += 1
- case "B":
- theB += 1
- case "C":
- theC += 1
- case "D":
- theD += 1
- default:
- }
-
- // bingoList = append(bingoList, utils.LuckyDraw(prizeList))
- }
-
- resStr := `A ==> %d B ==> %d C ==> %d D ==> %d`
-
- t.Fatalf(resStr, theA, theB, theC, theD)
- }
|