You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
968 B
42 lines
968 B
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func tod(s string) TimeOfDay {
|
|
tod, err := ParseTimeOfDay(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return tod
|
|
}
|
|
|
|
func TestTimeOfDay_IsBetween(t *testing.T) {
|
|
table := []struct{
|
|
Value TimeOfDay
|
|
From TimeOfDay
|
|
To TimeOfDay
|
|
Expected bool
|
|
}{
|
|
{ tod("16:13:11"), tod("07"), tod("21:30"), true },
|
|
{ tod("16:13:31"), tod("21:30"), tod("07"), false },
|
|
{ tod("23:15:32"), tod("21:30"), tod("07"), true },
|
|
{ tod("04:13:57"), tod("21:30"), tod("07"), true },
|
|
{ tod("16:14:43"), tod("15:30"), tod("16:00"), false },
|
|
{ tod("16:14:43"), tod("15:30"), tod("16:15"), true },
|
|
{ tod("08:45:43"), tod("07:00:00"), tod("21:30:00"), true },
|
|
{ tod("07:00:00"), tod("07:00:00"), tod("21:30:00"), true },
|
|
}
|
|
|
|
for i, row := range table {
|
|
t.Run(fmt.Sprintf("row_%d", i), func (t *testing.T) {
|
|
if row.Value.IsBetween(row.From, row.To) != row.Expected {
|
|
t.Log(row.Value, row.From, row.To)
|
|
t.Fail()
|
|
}
|
|
})
|
|
}
|
|
}
|