-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendarweek_test.go
67 lines (50 loc) · 1.78 KB
/
calendarweek_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
package main
import (
"testing"
"time"
)
func TestReturnCalendarWeekIfChanged(t *testing.T) {
var returnValue = 1
it := calendarWeekIteratorWithCustomProvider(10*time.Millisecond, func() int {
return returnValue
})
cw := <-it.ChangedCh
if cw != returnValue {
t.Errorf("Return value was incorrect, got: %d, want: %d.", cw, returnValue)
}
timeout := time.NewTimer(100 * time.Millisecond)
select {
case <-it.ChangedCh:
t.Errorf("Should not be called if not changed")
case <-timeout.C:
// we want the timeout to be hit, so we can validate that the function does not return an unchanged value
break
}
returnValue = 2
cw2 := <-it.ChangedCh
if cw2 != returnValue {
t.Errorf("Return value was incorrect, got: %d, want: %d.", cw, returnValue)
}
}
func TestOffsetCalendarWeekToDate_WithNoOffset(t *testing.T) {
week, startDate := offsetCalendarWeekToDateFromDate(0, time.Date(2019, time.October, 13, 0, 0, 0, 0, time.Local))
expectedWeek := 41
expectedStartDate := time.Date(2019, time.October, 7, 0, 0, 0, 0, time.Local)
if week != expectedWeek {
t.Errorf("The week was incorrect, got: %d, want: %d.", week, expectedWeek)
}
if startDate != expectedStartDate {
t.Errorf("The startdate was incorrect, got: %s, want: %s.", startDate, expectedStartDate)
}
}
func TestOffsetCalendarWeekToDate_WithOneOffset(t *testing.T) {
week, startDate := offsetCalendarWeekToDateFromDate(1, time.Date(2019, time.October, 13, 0, 0, 0, 0, time.Local))
expectedWeek := 42
expectedStartDate := time.Date(2019, time.October, 14, 0, 0, 0, 0, time.Local)
if week != expectedWeek {
t.Errorf("The week was incorrect, got: %d, want: %d.", week, expectedWeek)
}
if startDate != expectedStartDate {
t.Errorf("The startdate was incorrect, got: %s, want: %s.", startDate, expectedStartDate)
}
}