Skip to content
Snippets Groups Projects
Commit 814cc568 authored by Peter Fogg's avatar Peter Fogg
Browse files

Display rounded problem results.

parent ac0d7962
No related branches found
No related tags found
No related merge requests found
......@@ -116,12 +116,15 @@ class Progress(object):
return not self.__eq__(other)
def __str__(self):
''' Return a string representation of this string.
'''Return a string representation of this string. Rounds results to
two decimal places, stripping out any trailing zeroes.
subclassing note: implemented in terms of frac().
'''
(a, b) = self.frac()
return "{0}/{1}".format(a, b)
display = lambda n: '{:.2f}'.format(n).rstrip('0').rstrip('.')
return "{0}/{1}".format(display(a), display(b))
@staticmethod
def add_counts(a, b):
......
......@@ -81,6 +81,9 @@ class ProgressTest(unittest.TestCase):
self.assertEqual(str(self.not_started), "0/17")
self.assertEqual(str(self.part_done), "2/6")
self.assertEqual(str(self.done), "7/7")
self.assertEqual(str(Progress(2.1234, 7)), '2.12/7')
self.assertEqual(str(Progress(2.0034, 7)), '2/7')
self.assertEqual(str(Progress(0.999, 7)), '1/7')
def test_ternary_str(self):
self.assertEqual(self.not_started.ternary_str(), "none")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment