-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLotteryL649_test.go
162 lines (152 loc) · 3.27 KB
/
LotteryL649_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package TWLotteryCrawer
import (
_ "embed"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
"time"
)
//go:embed test_resources/lotto649_history.html
var L649HistoryPage string
type LotteryL649Suite struct {
suite.Suite
}
func (l *LotteryL649Suite) SetupSuite() {
httpmock.Activate()
httpmock.RegisterResponder("GET", "https://www.taiwanlottery.com.tw/lotto/Lotto649/history.aspx", httpmock.NewStringResponder(200, L649HistoryPage))
}
func (l *LotteryL649Suite) TearDownSuite() {
httpmock.DeactivateAndReset()
}
func (l *LotteryL649Suite) TestParseResultL649() {
results, err := ParseL649FromHistoryPage()
if err != nil {
l.Fail("Fail to parse L649 history page!")
}
r := results[0]
//Can't put time.Time, mock one
t := time.Now()
r.Date = t
expectedResult := L649Result{
Regular: []int{36, 1, 41, 17, 40, 5},
RegularSorted: []int{1, 5, 17, 36, 40, 41},
Special: 38,
Serial: "110000077",
Date: t,
FirstPrize: 451365562,
SecondPrize: 2374773,
ThirdPrize: 57470,
ForthPrize: 14679,
RolloverFP: 451365562,
RolloverSP: 0,
RolloverTP: 0,
RolloverForthP: 0,
}
assert.Equal(l.T(), expectedResult, r)
}
func (l *LotteryL649Suite) TestSuperLotto638Result_RewardOf() {
type args struct {
numbers []int
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "supposed be 普獎",
args: args{
numbers: []int{1, 2, 3, 4, 5, 17},
},
want: "普獎",
wantErr: false,
},
{
name: "supposed be 柒獎",
args: args{
numbers: []int{5, 8, 17, 20, 26, 38},
},
want: "柒獎",
wantErr: false,
},
{
name: "supposed be 陸獎",
args: args{
numbers: []int{5, 8, 17, 20, 36, 38},
},
want: "陸獎",
wantErr: false,
},
{
name: "supposed be 伍獎",
args: args{
numbers: []int{5, 8, 17, 26, 36, 41},
},
want: "伍獎",
wantErr: false,
},
{
name: "supposed be 肆獎",
args: args{
numbers: []int{5, 17, 36, 38, 39, 41},
},
want: "肆獎",
wantErr: false,
},
{
name: "supposed be 參獎",
args: args{
numbers: []int{1, 5, 16, 36, 40, 41},
},
want: "參獎",
wantErr: false,
},
{
name: "supposed be 貳獎",
args: args{
numbers: []int{5, 17, 36, 38, 40, 41},
},
want: "貳獎",
wantErr: false,
},
{
name: "supposed be 頭獎",
args: args{
numbers: []int{1, 5, 17, 36, 40, 41},
},
want: "頭獎",
wantErr: false,
},
{
name: "supposed be 沒中",
args: args{
numbers: []int{4, 7, 18, 20, 26, 36},
},
want: "沒中獎,再接再厲",
wantErr: false,
},
}
for _, tt := range tests {
l.Run(tt.name, func() {
results, err := ParseL649FromHistoryPage()
if err != nil {
l.Fail("Fail to parse SL638 Page")
}
result := results[0]
reward, err := result.RewardOf(tt.args.numbers)
if (err != nil) != tt.wantErr {
l.Failf("RewardOf() error = %s, wantErr %v", err.Error(), tt.wantErr)
return
}
got := reward.Title
if got != tt.want {
l.Failf("RewardOf() got = %s, want %s", got, tt.want)
}
})
}
}
func TestLotteryL649Suite(t *testing.T) {
suite.Run(t, new(LotteryL649Suite))
}