Merge pull request #9034 from edx/peter-fogg/round-grades

WIP: Display rounded problem results.
This commit is contained in:
Peter Fogg
2015-07-24 14:55:50 -04:00
2 changed files with 8 additions and 2 deletions

View File

@@ -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):

View File

@@ -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")