-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell_test.go
59 lines (48 loc) · 1.08 KB
/
cell_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
package timetable_test
import (
"log"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/portfoliotree/timetable"
)
type (
Value = int
Cell = timetable.Cell[Value]
)
const (
day0 = "2022-10-20" // Thursday
day1 = "2022-10-21" // Friday
day2 = "2022-10-24" // Monday
day3 = "2022-10-25" // Tuesday
firstDay = day0
lastDay = day3
dayBefore = "2022-10-19"
dayAfter = "2022-10-26"
)
func date(value string) time.Time {
t, err := time.Parse(time.DateOnly, value)
if err != nil {
log.Fatal(err)
}
return t
}
func elT(t string) Cell {
return timetable.NewCell[Value](date(t), 0)
}
func elV(t string, v Value) Cell {
return timetable.NewCell[Value](date(t), v)
}
func TestCell_Time(t *testing.T) {
cell := elT(day0)
assert.Equal(t, date(day0), cell.Time())
}
func TestCell_Value(t *testing.T) {
cell := elV(day0, 50)
assert.Equal(t, 50, cell.Value())
}
func TestCell_GoString(t *testing.T) {
cell := elV(day0, 1)
const s = `timetable.Cell[int]{time: "2022-10-20 00:00:00 +0000 UTC", value: 1}`
assert.Equal(t, s, cell.GoString())
}