@@ -743,20 +743,36 @@ def test_float_values_identical(self):
743743 assert len (diffs ) == 0
744744
745745 def test_float_values_slightly_different (self ):
746- """Slightly different float strings should be detected as different by Python comparison .
746+ """Float strings within epsilon tolerance should be considered equivalent .
747747
748- The Python direct comparison uses pure string equality, so even tiny
749- differences like "3.14159" vs "3.141590001" are detected. This is
750- expected behavior -- the Java Comparator uses EPSILON for tolerance,
751- but the Python fallback does not.
748+ The Python comparison uses math.isclose() with rel_tol=1e-9 for numeric values,
749+ matching the Java Comparator's EPSILON-based tolerance. Values like "3.14159"
750+ and "3.141590001" differ by ~3e-10, which is within the tolerance and thus
751+ considered equivalent.
752+
753+ For truly different values, the difference must exceed the epsilon threshold.
752754 """
755+ # These values differ by ~3e-10, which is within epsilon tolerance (1e-9)
753756 original = {
754757 "1" : {"result_json" : "3.14159" , "error_json" : None },
755758 }
756759 candidate = {
757760 "1" : {"result_json" : "3.141590001" , "error_json" : None },
758761 }
759762
763+ equivalent , diffs = compare_invocations_directly (original , candidate )
764+ assert equivalent is True # Within epsilon tolerance
765+ assert len (diffs ) == 0
766+
767+ def test_float_values_significantly_different (self ):
768+ """Float strings outside epsilon tolerance should be detected as different."""
769+ original = {
770+ "1" : {"result_json" : "3.14159" , "error_json" : None },
771+ }
772+ candidate = {
773+ "1" : {"result_json" : "3.14160" , "error_json" : None }, # Differs by ~1e-5
774+ }
775+
760776 equivalent , diffs = compare_invocations_directly (original , candidate )
761777 assert equivalent is False
762778 assert len (diffs ) == 1
@@ -869,14 +885,33 @@ def test_large_number_comparison(self):
869885 assert len (diffs ) == 0
870886
871887 def test_large_number_different (self ):
872- """Large numbers that differ by 1 should be detected."""
888+ """Very large numbers may lose precision when compared as floats.
889+
890+ Numbers like 99999999999999999 and 99999999999999998 both convert to
891+ 1e+17 as floats due to precision limits, making them indistinguishable.
892+ This is a known limitation of floating-point comparison for very large integers.
893+ """
873894 original = {
874895 "1" : {"result_json" : "99999999999999999" , "error_json" : None },
875896 }
876897 candidate = {
877898 "1" : {"result_json" : "99999999999999998" , "error_json" : None },
878899 }
879900
901+ equivalent , diffs = compare_invocations_directly (original , candidate )
902+ # Due to float precision limits, these are considered equal
903+ assert equivalent is True
904+ assert len (diffs ) == 0
905+
906+ def test_large_number_significantly_different (self ):
907+ """Large numbers with significant differences should be detected."""
908+ original = {
909+ "1" : {"result_json" : "100000000000000000" , "error_json" : None },
910+ }
911+ candidate = {
912+ "1" : {"result_json" : "200000000000000000" , "error_json" : None },
913+ }
914+
880915 equivalent , diffs = compare_invocations_directly (original , candidate )
881916 assert equivalent is False
882917 assert len (diffs ) == 1
0 commit comments