From c3a51618215bd77a5d79a32c4ef79076bdc485ff Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Wed, 18 Mar 2026 00:33:18 +0100 Subject: [PATCH 1/2] Add symmetric tests instead of duplicating them with swapped arguments. This is to ensure that the function being tested is symmetric in its arguments, which is a common expectation for equality checks. --- assert/assertions_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index da3eb4228..43b0412be 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -123,6 +123,11 @@ func TestObjectsAreEqual(t *testing.T) { {time.Now, time.Now, false}, {func() {}, func() {}, false}, {uint32(10), int32(10), false}, + {math.NaN(), math.NaN(), false}, + {math.Inf(1), math.Inf(1), true}, + {math.Inf(-1), math.Inf(-1), true}, + {math.Inf(1), math.Inf(-1), false}, + {math.Copysign(0, -1), 0.0, true}, // -0 should compare equal to 0 } for _, c := range cases { @@ -132,6 +137,10 @@ func TestObjectsAreEqual(t *testing.T) { if res != c.result { t.Errorf("ObjectsAreEqual(%#v, %#v) should return %#v", c.expected, c.actual, c.result) } + + if ObjectsAreEqual(c.actual, c.expected) != res { + 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) + } }) } } @@ -148,20 +157,15 @@ func TestObjectsAreEqualValues(t *testing.T) { }{ {uint32(10), int32(10), true}, {0, nil, false}, - {nil, 0, false}, {now, now.In(time.Local), false}, // should not be time zone independent {int(270), int8(14), false}, // should handle overflow/underflow - {int8(14), int(270), false}, {[]int{270, 270}, []int8{14, 14}, false}, {complex128(1e+100 + 1e+100i), complex64(complex(math.Inf(0), math.Inf(0))), false}, {complex64(complex(math.Inf(0), math.Inf(0))), complex128(1e+100 + 1e+100i), false}, {complex128(1e+100 + 1e+100i), 270, false}, {270, complex128(1e+100 + 1e+100i), false}, {complex128(1e+100 + 1e+100i), 3.14, false}, - {3.14, complex128(1e+100 + 1e+100i), false}, {complex128(1e+10 + 1e+10i), complex64(1e+10 + 1e+10i), true}, - {complex64(1e+10 + 1e+10i), complex128(1e+10 + 1e+10i), true}, - {float32(10.1), float64(10.1), true}, {float64(10.1), float32(10.1), true}, {float32(10.123456), float64(10.12345600), true}, {float32(10.123456), float64(10.12345678), false}, @@ -175,6 +179,10 @@ func TestObjectsAreEqualValues(t *testing.T) { if res != c.result { t.Errorf("ObjectsAreEqualValues(%#v, %#v) should return %#v", c.expected, c.actual, c.result) } + + if ObjectsAreEqualValues(c.actual, c.expected) != res { + 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) + } }) } } From 15e768d346e12835386b96f188f15467f18bc466 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Wed, 18 Mar 2026 08:23:41 +0100 Subject: [PATCH 2/2] Add unit tests about float32 vs float64 comparaison --- assert/assertions_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 43b0412be..a3ee918ab 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -170,6 +170,23 @@ func TestObjectsAreEqualValues(t *testing.T) { {float32(10.123456), float64(10.12345600), true}, {float32(10.123456), float64(10.12345678), false}, {float32(1.0 / 3.0), float64(1.0 / 3.0), false}, + + // Something near overflow should work + {float32(math.MaxFloat32), float64(math.MaxFloat32), true}, + + // NaN should remain unequal, even across float32/float64. + {float32(math.NaN()), float64(math.NaN()), false}, + + // Infinity should compare like ordinary equality. + {float32(math.Inf(1)), float64(math.Inf(1)), true}, + {float32(math.Inf(-1)), float64(math.Inf(-1)), true}, + {float64(math.Inf(1)), float32(math.Inf(-1)), false}, + + // zero should not lead to division by zero error + {float32(0), float64(0), true}, + + // Signed zero should still compare equal. + {float32(math.Copysign(0, -1)), float64(0), true}, } for _, c := range cases {