Skip to content

Commit 5ee3993

Browse files
committed
fix: πŸ› Fix rounding errors
1 parent 7cc8324 commit 5ee3993

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

β€Žcodelimit/common/report/Report.pyβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def all_report_units_sorted_by_length_asc(self, threshold=0) -> list[ReportUnit]
4343
result = sorted(result, key=lambda unit: unit.measurement.value, reverse=True)
4444
return result
4545

46-
def quality_profile(self):
46+
def quality_profile(self) -> list[int]:
4747
return make_profile(self.codebase.all_measurements())
4848

4949
def quality_profile_percentage(self):
5050
profile = self.quality_profile()
5151
total = sum(profile)
52-
unmaintainable = ceil((profile[3] / total) * 100) if total > 0 else 0
53-
hard_to_maintain = ceil((profile[2] / total) * 100) if total > 0 else 0
54-
verbose = ceil((profile[1] / total) * 100) if total > 0 else 0
52+
unmaintainable = ceil((profile[3] / total) * 100 - 0.001) if total > 0 else 0
53+
hard_to_maintain = ceil((profile[2] / total) * 100 - 0.001) if total > 0 else 0
54+
verbose = ceil((profile[1] / total) * 100 - 0.001) if total > 0 else 0
5555
easy = 100 - unmaintainable - hard_to_maintain - verbose
5656
return easy, verbose, hard_to_maintain, unmaintainable

β€Žtests/common/report/test_Report.pyβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def test_quality_profile_percentage():
1818
assert report.quality_profile_percentage() == (100, 0, 0, 0)
1919

2020

21+
def test_quality_profile_percentage_rounding():
22+
report = Report(Codebase("/"))
23+
report.quality_profile = lambda: [2530, 2883, 1395, 0]
24+
assert report.quality_profile_percentage() == (36, 43, 21, 0)
25+
26+
report.quality_profile = lambda: [630, 300, 70, 0]
27+
assert report.quality_profile_percentage() == (63, 30, 7, 0)
28+
2129
def test_all_units():
2230
codebase = Codebase("/")
2331
codebase.add_file(

0 commit comments

Comments
Β (0)