63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
|
package models
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestEndDate(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
startDate Date
|
||
|
duration int
|
||
|
endDate Date
|
||
|
}{
|
||
|
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 10, Date{Week: 0, Day: 0, Hour: 8, Minute: 10}},
|
||
|
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 90, Date{Week: 0, Day: 0, Hour: 9, Minute: 30}}, // More than one hour
|
||
|
{Date{Week: 0, Day: 0, Hour: 8, Minute: 0}, 130, Date{Week: 0, Day: 0, Hour: 10, Minute: 10}}, // More than two hours
|
||
|
{Date{Week: 0, Day: 0, Hour: 8, Minute: 15}, 90, Date{Week: 0, Day: 0, Hour: 9, Minute: 45}}, // More than one hour and start not 0
|
||
|
{Date{Week: 0, Day: 0, Hour: 23, Minute: 15}, 90, Date{Week: 0, Day: 1, Hour: 0, Minute: 45}}, // More than one day
|
||
|
}
|
||
|
for _, tc := range testCases {
|
||
|
t.Run(fmt.Sprintf("%d:%d, Dauer %d", tc.startDate.Hour, tc.startDate.Minute, tc.duration), func(t *testing.T) {
|
||
|
got := GetEndDate(tc.startDate, tc.duration, false)
|
||
|
if got != tc.endDate {
|
||
|
t.Errorf("got %v; want %v", got, tc.endDate)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestDateLess(t *testing.T) {
|
||
|
testCases := []struct {
|
||
|
name string
|
||
|
first Date
|
||
|
second Date
|
||
|
less bool
|
||
|
}{
|
||
|
{"earlier day",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 0, Hour: 7, Minute: 10}, false},
|
||
|
{"earlier hour",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 7, Minute: 10}, false},
|
||
|
{"earlier minute",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 0}, false},
|
||
|
{"same date",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, false},
|
||
|
{"later minute",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 8, Minute: 20}, true},
|
||
|
{"later hour",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 9, Minute: 10}, true},
|
||
|
{"later day",
|
||
|
Date{Week: 0, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 2, Hour: 8, Minute: 10}, true},
|
||
|
{"week should not matter",
|
||
|
Date{Week: 1, Day: 1, Hour: 8, Minute: 10}, Date{Week: 0, Day: 1, Hour: 9, Minute: 30}, true},
|
||
|
}
|
||
|
for _, tc := range testCases {
|
||
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
got := DateLess(tc.first, tc.second)
|
||
|
if got != tc.less {
|
||
|
t.Errorf("got %t; want %t", got, tc.less)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|