@@ -123,6 +123,11 @@ func TestObjectsAreEqual(t *testing.T) {
123123 {time .Now , time .Now , false },
124124 {func () {}, func () {}, false },
125125 {uint32 (10 ), int32 (10 ), false },
126+ {math .NaN (), math .NaN (), false },
127+ {math .Inf (1 ), math .Inf (1 ), true },
128+ {math .Inf (- 1 ), math .Inf (- 1 ), true },
129+ {math .Inf (1 ), math .Inf (- 1 ), false },
130+ {math .Copysign (0 , - 1 ), 0.0 , true }, // -0 should compare equal to 0
126131 }
127132
128133 for _ , c := range cases {
@@ -132,6 +137,10 @@ func TestObjectsAreEqual(t *testing.T) {
132137 if res != c .result {
133138 t .Errorf ("ObjectsAreEqual(%#v, %#v) should return %#v" , c .expected , c .actual , c .result )
134139 }
140+
141+ if ObjectsAreEqual (c .actual , c .expected ) != res {
142+ t .Errorf ("ObjectsAreEqual should be symmetric: ObjectsAreEqual(%#v, %#v) should return the same as ObjectsAreEqual(%#v, %#v)" , c .expected , c .actual , c .actual , c .expected )
143+ }
135144 })
136145 }
137146}
@@ -148,24 +157,36 @@ func TestObjectsAreEqualValues(t *testing.T) {
148157 }{
149158 {uint32 (10 ), int32 (10 ), true },
150159 {0 , nil , false },
151- {nil , 0 , false },
152160 {now , now .In (time .Local ), false }, // should not be time zone independent
153161 {int (270 ), int8 (14 ), false }, // should handle overflow/underflow
154- {int8 (14 ), int (270 ), false },
155162 {[]int {270 , 270 }, []int8 {14 , 14 }, false },
156163 {complex128 (1e+100 + 1e+100i ), complex64 (complex (math .Inf (0 ), math .Inf (0 ))), false },
157164 {complex64 (complex (math .Inf (0 ), math .Inf (0 ))), complex128 (1e+100 + 1e+100i ), false },
158165 {complex128 (1e+100 + 1e+100i ), 270 , false },
159166 {270 , complex128 (1e+100 + 1e+100i ), false },
160167 {complex128 (1e+100 + 1e+100i ), 3.14 , false },
161- {3.14 , complex128 (1e+100 + 1e+100i ), false },
162168 {complex128 (1e+10 + 1e+10i ), complex64 (1e+10 + 1e+10i ), true },
163- {complex64 (1e+10 + 1e+10i ), complex128 (1e+10 + 1e+10i ), true },
164- {float32 (10.1 ), float64 (10.1 ), true },
165169 {float64 (10.1 ), float32 (10.1 ), true },
166170 {float32 (10.123456 ), float64 (10.12345600 ), true },
167171 {float32 (10.123456 ), float64 (10.12345678 ), false },
168172 {float32 (1.0 / 3.0 ), float64 (1.0 / 3.0 ), false },
173+
174+ // Something near overflow should work
175+ {float32 (math .MaxFloat32 ), float64 (math .MaxFloat32 ), true },
176+
177+ // NaN should remain unequal, even across float32/float64.
178+ {float32 (math .NaN ()), float64 (math .NaN ()), false },
179+
180+ // Infinity should compare like ordinary equality.
181+ {float32 (math .Inf (1 )), float64 (math .Inf (1 )), true },
182+ {float32 (math .Inf (- 1 )), float64 (math .Inf (- 1 )), true },
183+ {float64 (math .Inf (1 )), float32 (math .Inf (- 1 )), false },
184+
185+ // zero should not lead to division by zero error
186+ {float32 (0 ), float64 (0 ), true },
187+
188+ // Signed zero should still compare equal.
189+ {float32 (math .Copysign (0 , - 1 )), float64 (0 ), true },
169190 }
170191
171192 for _ , c := range cases {
@@ -175,6 +196,10 @@ func TestObjectsAreEqualValues(t *testing.T) {
175196 if res != c .result {
176197 t .Errorf ("ObjectsAreEqualValues(%#v, %#v) should return %#v" , c .expected , c .actual , c .result )
177198 }
199+
200+ if ObjectsAreEqualValues (c .actual , c .expected ) != res {
201+ t .Errorf ("ObjectsAreEqualValues should be symmetric: ObjectsAreEqualValues(%#v, %#v) should return the same as ObjectsAreEqualValues(%#v, %#v)" , c .expected , c .actual , c .actual , c .expected )
202+ }
178203 })
179204 }
180205}
0 commit comments