-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfortune_test.go
56 lines (45 loc) · 1023 Bytes
/
fortune_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
package lib
import (
"log"
"math/rand"
"testing"
"time"
"github.com/gopherdojo/dojo1/kadai4/matsuki/lib"
)
// TestMain called first
func TestMain(t *testing.T) {
beforeTest()
// test here
// TestIndex(t)
}
func beforeTest() {
rand.Seed(time.Now().UnixNano())
lib.Verbos = true
}
func TestDrawFortuneSlip(t *testing.T) {
f := lib.NewFortune(time.Now())
slip, _ := f.DrawFortuneSlip()
switch slip {
case "大吉", "中吉", "吉", "凶", "大凶":
log.Print("draw valid slip")
default:
t.Errorf("invalid slip=%v", slip)
}
}
func TestDrawWhenNewyear(t *testing.T) {
tm, err := time.Parse("2006-01-02", "2013-01-03")
log.Println("test date=", tm, err)
f := lib.NewFortune(tm)
slip, isNd := f.DrawFortuneSlip()
switch slip {
case "大吉":
log.Print("draw valid slip")
case "中吉", "吉", "凶", "大凶":
t.Errorf("today is newYear. invalid slip=%v", slip)
default:
t.Errorf("invalid slip=%v", slip)
}
if isNd != true {
t.Errorf("want isNewYearDay is true but %v", isNd)
}
}