6
6
"reflect"
7
7
"runtime"
8
8
"testing"
9
+ "time"
9
10
)
10
11
11
12
func TestCompare (t * testing.T ) {
@@ -22,6 +23,7 @@ func TestCompare(t *testing.T) {
22
23
type customFloat32 float32
23
24
type customFloat64 float64
24
25
type customString string
26
+ type customTime time.Time
25
27
for _ , currCase := range []struct {
26
28
less interface {}
27
29
greater interface {}
@@ -52,14 +54,17 @@ func TestCompare(t *testing.T) {
52
54
{less : customFloat32 (1.23 ), greater : customFloat32 (2.23 ), cType : "float32" },
53
55
{less : float64 (1.23 ), greater : float64 (2.34 ), cType : "float64" },
54
56
{less : customFloat64 (1.23 ), greater : customFloat64 (2.34 ), cType : "float64" },
57
+ {less : time .Now (), greater : time .Now ().Add (time .Hour ), cType : "time.Time" },
58
+ {less : customTime (time .Now ()), greater : customTime (time .Now ().Add (time .Hour )), cType : "time.Time" },
55
59
} {
56
60
resLess , isComparable := compare (currCase .less , currCase .greater , reflect .ValueOf (currCase .less ).Kind ())
57
61
if ! isComparable {
58
62
t .Error ("object should be comparable for type " + currCase .cType )
59
63
}
60
64
61
65
if resLess != compareLess {
62
- t .Errorf ("object less should be less than greater for type " + currCase .cType )
66
+ t .Errorf ("object less (%v) should be less than greater (%v) for type " + currCase .cType ,
67
+ currCase .less , currCase .greater )
63
68
}
64
69
65
70
resGreater , isComparable := compare (currCase .greater , currCase .less , reflect .ValueOf (currCase .less ).Kind ())
0 commit comments