mirror of
https://github.com/emirpasic/gods.git
synced 2026-06-14 16:06:42 +03:00
- time comparator fmt and documentation update
This commit is contained in:
+15
-15
@@ -53,21 +53,6 @@ func IntComparator(a, b interface{}) int {
|
||||
}
|
||||
}
|
||||
|
||||
// TimeComparator provides a basic comparison on time.Time
|
||||
func TimeComparator(a, b interface{}) int {
|
||||
aAsserted := a.(time.Time)
|
||||
bAsserted := b.(time.Time)
|
||||
|
||||
switch {
|
||||
case aAsserted.After(bAsserted) :
|
||||
return 1
|
||||
case aAsserted.Before(bAsserted):
|
||||
return -1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// Int8Comparator provides a basic comparison on int8
|
||||
func Int8Comparator(a, b interface{}) int {
|
||||
aAsserted := a.(int8)
|
||||
@@ -249,3 +234,18 @@ func RuneComparator(a, b interface{}) int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// TimeComparator provides a basic comparison on time.Time
|
||||
func TimeComparator(a, b interface{}) int {
|
||||
aAsserted := a.(time.Time)
|
||||
bAsserted := b.(time.Time)
|
||||
|
||||
switch {
|
||||
case aAsserted.After(bAsserted):
|
||||
return 1
|
||||
case aAsserted.Before(bAsserted):
|
||||
return -1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
+20
-21
@@ -31,27 +31,6 @@ func TestIntComparator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestTimeComparator(t *testing.T) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// i1,i2,expected
|
||||
tests := [][]interface{}{
|
||||
{now, now, 0},
|
||||
{now.Add(24 * 7 * 2 * time.Hour), now, 1},
|
||||
{now, now.Add(24 * 7 * 2 * time.Hour), -1},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
actual := TimeComparator(test[0], test[1])
|
||||
expected := test[2]
|
||||
if actual != expected {
|
||||
t.Errorf("Got %v expected %v", actual, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringComparator(t *testing.T) {
|
||||
|
||||
// s1,s2,expected
|
||||
@@ -75,6 +54,26 @@ func TestStringComparator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeComparator(t *testing.T) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
// i1,i2,expected
|
||||
tests := [][]interface{}{
|
||||
{now, now, 0},
|
||||
{now.Add(24 * 7 * 2 * time.Hour), now, 1},
|
||||
{now, now.Add(24 * 7 * 2 * time.Hour), -1},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
actual := TimeComparator(test[0], test[1])
|
||||
expected := test[2]
|
||||
if actual != expected {
|
||||
t.Errorf("Got %v expected %v", actual, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomComparator(t *testing.T) {
|
||||
|
||||
type Custom struct {
|
||||
|
||||
Reference in New Issue
Block a user