Skip to content

Instantly share code, notes, and snippets.

@gravataLonga
Created October 28, 2022 22:15
Show Gist options
  • Save gravataLonga/fb83fa74d336798afe34598bb76d9681 to your computer and use it in GitHub Desktop.
Save gravataLonga/fb83fa74d336798afe34598bb76d9681 to your computer and use it in GitHub Desktop.
Testing Overlapping date
package main
import (
"fmt"
"testing"
)
func TestOverlappingDate(t *testing.T) {
tests := []struct {
beginDateA string
endDateA string
beginDateB string
endDateB string
overlapping bool
}{
{
"2022-01-01",
"2022-01-05",
"2022-01-02",
"2022-01-03",
true,
},
{
"2022-01-10",
"2022-01-15",
"2022-01-01",
"2022-01-12",
true,
},
{
"2022-01-10",
"2022-01-15",
"2022-01-12",
"2022-01-20",
true,
},
{
"2022-01-10",
"2022-01-15",
"2022-01-08",
"2022-01-20",
true,
},
{
"2022-01-10",
"2022-01-15",
"2022-01-12",
"2022-01-13",
true,
},
{
"2022-01-01",
"2022-01-15",
"2022-01-20",
"2022-01-25",
false,
},
{
"2022-01-10",
"2022-01-15",
"2022-01-01",
"2022-01-08",
false,
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("Test [%d]", i), func(t *testing.T) {
result := overlappingDate(tt.beginDateA, tt.endDateA, tt.beginDateB, tt.endDateB)
if result != tt.overlapping {
t.Errorf("Test failed, expected %v. Got: %v", tt.overlapping, result)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment