-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10chapters_test.go
65 lines (58 loc) · 1.73 KB
/
10chapters_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
package main
import (
"testing"
"time"
)
// TestDaysSince tests the supported date format and that an
// unsupported date format returns an error and -1. Test that the
// provided date is inclusive.
func TestDaysSince(t *testing.T) {
today := time.Now().Format("2006-01-02")
sinceToday, err := daysSince(today)
if err != nil {
t.Log("daysSince with", today, "should not cause this error:")
t.Error(err)
}
if sinceToday != 1 {
t.Error("daysSince(today) should be 1, was", sinceToday)
}
germanDate := time.Now().Format("02.01.2006")
sinceGer, err := daysSince(germanDate)
if err == nil {
t.Error("daysSince with unsupported date format should cause an error")
}
if sinceGer != -1 {
t.Error("daysSince with unknown date format should be -1, was", sinceGer)
}
}
// TestGenerateListChapters checks the lengths of the gernated chapter
// lists and tests for a few expected values.
func TestGenerateListChapters(t *testing.T) {
lists := [10][]book{
[]book{book{"One", 1}, book{"Two", 2}},
[]book{book{"Two", 2}, book{"One", 1}},
[]book{book{"None", 0}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
[]book{book{"abc", 26}},
}
chapters := generateListChapters(lists)
lengths := []int{3, 3, 0, 26, 26, 26, 26, 26, 26, 26}
for i := 0; i < 10; i++ {
if len(chapters[i]) == lengths[i] {
continue
}
t.Errorf("Length of list %d doesn’t match, expected %d, was %d",
i, lengths[i], len(chapters[i]))
}
if chapters[0][1] != "Two 1" {
t.Error("chapters[0][1] should be “Two 1”, was", chapters[0][1])
}
if chapters[1][1] != "Two 2" {
t.Error("chapters[1][1] should be “Two 2”, was", chapters[1][1])
}
}