From 073bd746347ff6c1f9dbd18c453cbcebfe5b2171 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sat, 15 Aug 2015 17:18:19 -0700 Subject: [PATCH] nomad: test overflow --- nomad/timetable_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/nomad/timetable_test.go b/nomad/timetable_test.go index 9ae64fbce..5d94d854f 100644 --- a/nomad/timetable_test.go +++ b/nomad/timetable_test.go @@ -115,3 +115,32 @@ func TestTimeTable_SerializeDeserialize(t *testing.T) { t.Fatalf("bad: %#v %#v", tt, tt2) } } + +func TestTimeTable_Overflow(t *testing.T) { + tt := NewTimeTable(time.Second, 3*time.Second) + + // Witness some data + start := time.Now() + plusOne := start.Add(time.Second) + plusTwo := start.Add(2 * time.Second) + plusThree := start.Add(3 * time.Second) + + tt.Witness(10, start) + tt.Witness(20, plusOne) + tt.Witness(30, plusTwo) + tt.Witness(40, plusThree) + + if len(tt.table) != 3 { + t.Fatalf("bad") + } + + index := tt.NearestIndex(start) + if index != 0 { + t.Fatalf("bad: %v %v", index, 0) + } + + when := tt.NearestTime(15) + if !when.IsZero() { + t.Fatalf("bad: %v", when) + } +}