@@ -20,7 +20,7 @@ type zeroer interface {
20
20
IsZero () bool
21
21
}
22
22
23
- func TestTimestampCompare (t * testing.T ) {
23
+ func TestCompareTimestamp (t * testing.T ) {
24
24
testcases := []struct {
25
25
name string
26
26
tp Timestamp
@@ -42,6 +42,79 @@ func TestTimestampCompare(t *testing.T) {
42
42
}
43
43
}
44
44
45
+ func TestTimestamp (t * testing.T ) {
46
+ t .Parallel ()
47
+
48
+ testCases := []struct {
49
+ description string
50
+ tp Timestamp
51
+ tp2 Timestamp
52
+ expectedAfter bool
53
+ expectedBefore bool
54
+ expectedEqual bool
55
+ expectedCompare int
56
+ }{
57
+ {
58
+ description : "equal" ,
59
+ tp : Timestamp {T : 12345 , I : 67890 },
60
+ tp2 : Timestamp {T : 12345 , I : 67890 },
61
+ expectedBefore : false ,
62
+ expectedAfter : false ,
63
+ expectedEqual : true ,
64
+ expectedCompare : 0 ,
65
+ },
66
+ {
67
+ description : "T greater than" ,
68
+ tp : Timestamp {T : 12345 , I : 67890 },
69
+ tp2 : Timestamp {T : 2345 , I : 67890 },
70
+ expectedBefore : false ,
71
+ expectedAfter : true ,
72
+ expectedEqual : false ,
73
+ expectedCompare : 1 ,
74
+ },
75
+ {
76
+ description : "I greater than" ,
77
+ tp : Timestamp {T : 12345 , I : 67890 },
78
+ tp2 : Timestamp {T : 12345 , I : 7890 },
79
+ expectedBefore : false ,
80
+ expectedAfter : true ,
81
+ expectedEqual : false ,
82
+ expectedCompare : 1 ,
83
+ },
84
+ {
85
+ description : "T less than" ,
86
+ tp : Timestamp {T : 12345 , I : 67890 },
87
+ tp2 : Timestamp {T : 112345 , I : 67890 },
88
+ expectedBefore : true ,
89
+ expectedAfter : false ,
90
+ expectedEqual : false ,
91
+ expectedCompare : - 1 ,
92
+ },
93
+ {
94
+ description : "I less than" ,
95
+ tp : Timestamp {T : 12345 , I : 67890 },
96
+ tp2 : Timestamp {T : 12345 , I : 167890 },
97
+ expectedBefore : true ,
98
+ expectedAfter : false ,
99
+ expectedEqual : false ,
100
+ expectedCompare : - 1 ,
101
+ },
102
+ }
103
+
104
+ for _ , tc := range testCases {
105
+ tc := tc // Capture range variable.
106
+
107
+ t .Run (tc .description , func (t * testing.T ) {
108
+ t .Parallel ()
109
+
110
+ assert .Equal (t , tc .expectedAfter , tc .tp .After (tc .tp2 ), "expected After results to be the same" )
111
+ assert .Equal (t , tc .expectedBefore , tc .tp .Before (tc .tp2 ), "expected Before results to be the same" )
112
+ assert .Equal (t , tc .expectedEqual , tc .tp .Equal (tc .tp2 ), "expected Equal results to be the same" )
113
+ assert .Equal (t , tc .expectedCompare , tc .tp .Compare (tc .tp2 ), "expected Compare result to be the same" )
114
+ })
115
+ }
116
+ }
117
+
45
118
func TestPrimitiveIsZero (t * testing.T ) {
46
119
testcases := []struct {
47
120
name string
0 commit comments