-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_stop_test.go
64 lines (57 loc) · 1.26 KB
/
model_stop_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
// © 2019-present nextmv.io inc
package nextroute_test
import (
"fmt"
"testing"
"time"
"github.com/nextmv-io/nextroute"
"github.com/nextmv-io/nextroute/common"
)
func TestModelStop_ToEarliestStart(t *testing.T) {
model, err := nextroute.NewModel()
if err != nil {
t.Fatal(err)
}
s1, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
windows := [][2]float64{
{60, 120},
{240, 360},
{360, 420},
{480, 540},
}
windowsAsTime := make([][2]time.Time, len(windows))
for i, w := range windows {
windowsAsTime[i] = [2]time.Time{
model.Epoch().Add(time.Duration(w[0]) * model.DurationUnit()),
model.Epoch().Add(time.Duration(w[1]) * model.DurationUnit()),
}
}
err = s1.SetWindows(windowsAsTime)
if err != nil {
t.Fatal(err)
}
tests := []struct {
t float64
want float64
}{
{t: 0, want: 60},
{t: 120, want: 240},
{t: 130, want: 240},
{t: 240, want: 240},
{t: 300, want: 300},
{t: 480, want: 480},
{t: 539, want: 539},
{t: 540, want: 540},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v -> %v", tt.t, tt.want), func(_ *testing.T) {
earliest := s1.ToEarliestStartValue(tt.t)
if earliest != tt.want {
t.Errorf("got %v, want %v, at %v", earliest, tt.want, tt.t)
}
})
}
}