From 734bb606c7a79d06e71af1cab9060e358c27c9f8 Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 30 Sep 2026 10:56:44 +0530 Subject: [PATCH] Fix RationalFunction subtraction operator dispatch --- blueprint/src/python/functions.py | 2 +- blueprint/src/python/tests/test_all.py | 1 + .../python/tests/test_rational_subtraction.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 blueprint/src/python/tests/test_rational_subtraction.py diff --git a/blueprint/src/python/functions.py b/blueprint/src/python/functions.py index d369b50..b92c025 100644 --- a/blueprint/src/python/functions.py +++ b/blueprint/src/python/functions.py @@ -785,7 +785,7 @@ def __add__(self, other): return self.add(other) def __sub__(self, other): - return self.sub(other) + return self.subtract(other) def __mul__(self, other): return self.mul(other) diff --git a/blueprint/src/python/tests/test_all.py b/blueprint/src/python/tests/test_all.py index 65bab68..f4326df 100644 --- a/blueprint/src/python/tests/test_all.py +++ b/blueprint/src/python/tests/test_all.py @@ -36,6 +36,7 @@ import test_rationalfunction import test_rational_roots_regression +import test_rational_subtraction print("All RationalFunction test cases passed.") diff --git a/blueprint/src/python/tests/test_rational_subtraction.py b/blueprint/src/python/tests/test_rational_subtraction.py new file mode 100644 index 0000000..88f2eb0 --- /dev/null +++ b/blueprint/src/python/tests/test_rational_subtraction.py @@ -0,0 +1,17 @@ +from fractions import Fraction + +from functions import RationalFunction + + +def test_subtraction_operator(): + f = RationalFunction([1, 1], [1, 2]) + g = RationalFunction([2, 1], [1, 3]) + for other in (g, 2, Fraction(1, 3)): + result = f - other + for x in (Fraction(0), Fraction(1), Fraction(3, 2)): + expected = f.at(x) - (other.at(x) if isinstance(other, RationalFunction) else other) + assert result.at(x) == expected + assert (f - f).at(Fraction(1)) == 0 + + +test_subtraction_operator()