From 37f738cc71b3f59e83f08d4fd9712d41ae7f9cef Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 28 May 2024 14:56:53 -0500 Subject: [PATCH] Changed RFrac equality in scripts Now, fractions are considered equal if they have the same ratio: - 6/6 == 12/12 => True - 3/6 == 3/12 => False - 1/6 == 2/12 => True It's interesting to note this implementation is actually more numerically stable than float comparison, though that wasn't really the goal. The main reason for this is to allow other fields to take over when sorting multi-field fractional data: cov (lines + branches), testmarks (passed + time), etc. Before, sorting would usually stop after mismatched fraction fields, which wasn't all that useful. --- Makefile | 2 +- scripts/cov.py | 14 +++++++++++--- scripts/summary.py | 14 +++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 04b1e36b..4d3182cc 100644 --- a/Makefile +++ b/Makefile @@ -393,7 +393,7 @@ test-list list-tests: test-runner ## Summarize the test results .PHONY: testmarks -testmarks: SUMMARYFLAGS+=-Stime +testmarks: SUMMARYFLAGS+=-spassed -Stime testmarks: $(TEST_CSV) $(BUILDDIR)/lfs.test.csv $(strip ./scripts/summary.py $(TEST_CSV) \ -bsuite \ diff --git a/scripts/cov.py b/scripts/cov.py index e75c76f3..0b44e2a2 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -154,10 +154,18 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): def __mul__(self, other): return self.__class__(self.a * other.a, self.b + other.b) + def __eq__(self, other): + self_a, self_b = self if self.b.x else (RInt(1), RInt(1)) + other_a, other_b = other if other.b.x else (RInt(1), RInt(1)) + return self_a * other_b == other_a * self_b + + def __ne__(self, other): + return not self.__eq__(other) + def __lt__(self, other): - self_t = self.a.x/self.b.x if self.b.x else 1.0 - other_t = other.a.x/other.b.x if other.b.x else 1.0 - return (self_t, self.a.x) < (other_t, other.a.x) + self_a, self_b = self if self.b.x else (RInt(1), RInt(1)) + other_a, other_b = other if other.b.x else (RInt(1), RInt(1)) + return self_a * other_b < other_a * self_b def __gt__(self, other): return self.__class__.__lt__(other, self) diff --git a/scripts/summary.py b/scripts/summary.py index c41296e7..997d9d0d 100755 --- a/scripts/summary.py +++ b/scripts/summary.py @@ -220,10 +220,18 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): def __mul__(self, other): return self.__class__(self.a * other.a, self.b + other.b) + def __eq__(self, other): + self_a, self_b = self if self.b.x else (RInt(1), RInt(1)) + other_a, other_b = other if other.b.x else (RInt(1), RInt(1)) + return self_a * other_b == other_a * self_b + + def __ne__(self, other): + return not self.__eq__(other) + def __lt__(self, other): - self_t = self.a.x/self.b.x if self.b.x else 1.0 - other_t = other.a.x/other.b.x if other.b.x else 1.0 - return (self_t, self.a.x) < (other_t, other.a.x) + self_a, self_b = self if self.b.x else (RInt(1), RInt(1)) + other_a, other_b = other if other.b.x else (RInt(1), RInt(1)) + return self_a * other_b < other_a * self_b def __gt__(self, other): return self.__class__.__lt__(other, self)