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

  1. package models
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func tod(s string) TimeOfDay {
  7. tod, err := ParseTimeOfDay(s)
  8. if err != nil {
  9. panic(err)
  10. }
  11. return tod
  12. }
  13. func TestTimeOfDay_IsBetween(t *testing.T) {
  14. table := []struct{
  15. Value TimeOfDay
  16. From TimeOfDay
  17. To TimeOfDay
  18. Expected bool
  19. }{
  20. { tod("16:13:11"), tod("07"), tod("21:30"), true },
  21. { tod("16:13:31"), tod("21:30"), tod("07"), false },
  22. { tod("23:15:32"), tod("21:30"), tod("07"), true },
  23. { tod("04:13:57"), tod("21:30"), tod("07"), true },
  24. { tod("16:14:43"), tod("15:30"), tod("16:00"), false },
  25. { tod("16:14:43"), tod("15:30"), tod("16:15"), true },
  26. { tod("08:45:43"), tod("07:00:00"), tod("21:30:00"), true },
  27. { tod("07:00:00"), tod("07:00:00"), tod("21:30:00"), true },
  28. }
  29. for i, row := range table {
  30. t.Run(fmt.Sprintf("row_%d", i), func (t *testing.T) {
  31. if row.Value.IsBetween(row.From, row.To) != row.Expected {
  32. t.Log(row.Value, row.From, row.To)
  33. t.Fail()
  34. }
  35. })
  36. }
  37. }