Example #1
0
    def testRounding(self, i):
        """ Rounding various values according to various methods. """
        f = Fraction(i, 10)
        self.assertEqual(round_fraction(f, RoundingMethods.ROUND_DOWN), 0)
        self.assertEqual(round_fraction(f, RoundingMethods.ROUND_UP), 1)

        r = round_fraction(f, RoundingMethods.ROUND_HALF_UP)
        if i < 5:
            self.assertEqual(r, 0)
        else:
            self.assertEqual(r, 1)

        r = round_fraction(f, RoundingMethods.ROUND_HALF_DOWN)
        if i > 5:
            self.assertEqual(r, 1)
        else:
            self.assertEqual(r, 0)
Example #2
0
 def testExceptions(self):
     """ Raises exception on bad input. """
     with self.assertRaises(SizeValueError):
         round_fraction(Fraction(13, 32), "a string")
     with self.assertRaises(SizeValueError):
         round_fraction(Fraction(16, 32), "a string")