47 lines
1.9 KiB
Go
47 lines
1.9 KiB
Go
package server_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.javil.eu/jacob1123/budgeteer/server"
|
|
)
|
|
|
|
type TestCaseCompare struct {
|
|
Value server.Month
|
|
Date time.Time
|
|
InPast bool
|
|
InPresent bool
|
|
InFuture bool
|
|
}
|
|
|
|
func TestComparisons(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
loc := time.Now().Location()
|
|
tests := []TestCaseCompare{
|
|
{server.Month{2022, 2}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), false, false, true},
|
|
{server.Month{2022, 3}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), false, true, false},
|
|
{server.Month{2022, 4}, time.Date(2022, 3, 1, 0, 0, 0, 0, loc), true, false, false},
|
|
{server.Month{2022, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
|
|
{server.Month{2022, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, true, false},
|
|
{server.Month{2022, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
|
|
{server.Month{2021, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
|
|
{server.Month{2021, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
|
|
{server.Month{2021, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), false, false, true},
|
|
{server.Month{2023, 2}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
|
|
{server.Month{2023, 3}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
|
|
{server.Month{2023, 4}, time.Date(2022, 3, 31, 0, 0, 0, 0, loc), true, false, false},
|
|
{server.Month{2021, 11}, time.Date(2021, 12, 1, 0, 0, 0, 0, loc), false, false, true},
|
|
}
|
|
for i := range tests { //nolint:paralleltest
|
|
test := tests[i]
|
|
t.Run(test.Date.Format("2006-01-02")+" is in of "+test.Value.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
server.AssertEqualBool(t, test.InPast, test.Value.InPast(test.Date), "in past")
|
|
server.AssertEqualBool(t, test.InPresent, test.Value.InPresent(test.Date), "in present")
|
|
server.AssertEqualBool(t, test.InFuture, test.Value.InFuture(test.Date), "in future")
|
|
})
|
|
}
|
|
}
|