mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-10 01:02:56 +08:00
test(number-convert): add precision tests for large integers
Cover the reported precision loss scenario and related edge cases: - String inputs beyond 2^53 (positive, negative, very large) - Native int inputs beyond 2^53 - Decimal string fallback behavior - Large scientific notation strings (1e18) - Type assertion for FLOAT output of large int strings
This commit is contained in:
parent
8bc08b0e70
commit
30ebfa6ff6
@ -90,6 +90,63 @@ class TestNumberConvertExecute:
|
|||||||
assert result[0] == 1000.0
|
assert result[0] == 1000.0
|
||||||
assert result[1] == 1000
|
assert result[1] == 1000
|
||||||
|
|
||||||
|
# --- Large number precision (string input) ---
|
||||||
|
|
||||||
|
def test_string_large_int_above_2_53(self):
|
||||||
|
"""Text-to-int must not lose precision for integers beyond 2^53."""
|
||||||
|
big = 2**53 + 1 # 9007199254740993
|
||||||
|
result = self._exec(str(big))
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
def test_string_large_negative_int_above_2_53(self):
|
||||||
|
big = -(2**53 + 1)
|
||||||
|
result = self._exec(str(big))
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
def test_string_very_large_int(self):
|
||||||
|
big = 2**63 + 42
|
||||||
|
result = self._exec(str(big))
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
def test_string_large_int_float_output_is_float(self):
|
||||||
|
"""FLOAT output is still a float (may lose precision, but must be float type)."""
|
||||||
|
result = self._exec(str(2**53 + 1))
|
||||||
|
assert isinstance(result[0], float)
|
||||||
|
|
||||||
|
# --- Large number precision (int input) ---
|
||||||
|
|
||||||
|
def test_int_large_above_2_53(self):
|
||||||
|
"""Native int input must preserve its value in the INT output."""
|
||||||
|
big = 2**53 + 1
|
||||||
|
result = self._exec(big)
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
def test_int_large_negative_above_2_53(self):
|
||||||
|
big = -(2**53 + 1)
|
||||||
|
result = self._exec(big)
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
def test_int_very_large(self):
|
||||||
|
big = 2**100
|
||||||
|
result = self._exec(big)
|
||||||
|
assert result[1] == big
|
||||||
|
|
||||||
|
# --- String decimal / scientific notation fallback ---
|
||||||
|
|
||||||
|
def test_string_decimal_still_truncates(self):
|
||||||
|
"""Strings with decimal points fall back to int(float(...)) truncation."""
|
||||||
|
result = self._exec("3.7")
|
||||||
|
assert result[1] == 3
|
||||||
|
|
||||||
|
def test_string_negative_decimal_truncates(self):
|
||||||
|
result = self._exec("-2.9")
|
||||||
|
assert result[1] == -2
|
||||||
|
|
||||||
|
def test_string_scientific_large(self):
|
||||||
|
result = self._exec("1e18")
|
||||||
|
assert result[0] == 1e18
|
||||||
|
assert result[1] == 10**18
|
||||||
|
|
||||||
# --- STRING error paths ---
|
# --- STRING error paths ---
|
||||||
|
|
||||||
def test_empty_string_raises(self):
|
def test_empty_string_raises(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user