github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/internal/schedule/day_time_test.go (about) 1 package schedule_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/martinohmann/rfoutlet/internal/schedule" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestDayTimeBefore(t *testing.T) { 12 tests := []struct { 13 a schedule.DayTime 14 b schedule.DayTime 15 expected bool 16 }{ 17 { 18 a: schedule.NewDayTime(10, 0), 19 b: schedule.NewDayTime(12, 0), 20 expected: true, 21 }, 22 { 23 a: schedule.NewDayTime(10, 0), 24 b: schedule.NewDayTime(10, 1), 25 expected: true, 26 }, 27 { 28 a: schedule.NewDayTime(10, 0), 29 b: schedule.NewDayTime(10, 0), 30 expected: false, 31 }, 32 { 33 a: schedule.NewDayTime(10, 0), 34 b: schedule.NewDayTime(9, 59), 35 expected: false, 36 }, 37 { 38 a: schedule.NewDayTime(0, 0), 39 b: schedule.NewDayTime(23, 59), 40 expected: true, 41 }, 42 } 43 44 for _, tt := range tests { 45 assert.Equal(t, tt.expected, tt.a.Before(tt.b), 46 fmt.Sprintf("a=%v, b=%v", tt.a, tt.b)) 47 } 48 } 49 50 func TestDayTimeAfter(t *testing.T) { 51 tests := []struct { 52 a schedule.DayTime 53 b schedule.DayTime 54 expected bool 55 }{ 56 { 57 a: schedule.NewDayTime(10, 0), 58 b: schedule.NewDayTime(12, 0), 59 expected: false, 60 }, 61 { 62 a: schedule.NewDayTime(10, 0), 63 b: schedule.NewDayTime(10, 1), 64 expected: false, 65 }, 66 { 67 a: schedule.NewDayTime(10, 0), 68 b: schedule.NewDayTime(10, 0), 69 expected: false, 70 }, 71 { 72 a: schedule.NewDayTime(10, 0), 73 b: schedule.NewDayTime(9, 59), 74 expected: true, 75 }, 76 { 77 a: schedule.NewDayTime(23, 59), 78 b: schedule.NewDayTime(0, 0), 79 expected: true, 80 }, 81 { 82 a: schedule.NewDayTime(0, 0), 83 b: schedule.NewDayTime(23, 59), 84 expected: false, 85 }, 86 } 87 88 for _, tt := range tests { 89 assert.Equal(t, tt.expected, tt.a.After(tt.b), 90 fmt.Sprintf("a=%v, b=%v", tt.a, tt.b)) 91 } 92 }