Exemple #1
0
 def testMoreComplexRepeatingDecimal(self, divisor, multiplier):
     """
     Should always end in .142857142857....
     """
     dividend = Fraction(divisor) * (multiplier + Fraction(1, 7))
     res = long_decimal_division(divisor, dividend)
     self.assertEqual(res[3], [1, 4, 2, 8, 5, 7])
     self.assertEqual(res[2], [])
     self.assertEqual(res[1], multiplier)
     self.assertEqual(res[0], 1)
Exemple #2
0
 def testComplexRepeatingDecimal(self, divisor, multiplier):
     """
     Should always end in .16666.....
     """
     dividend = Fraction(divisor) * (multiplier + Fraction(1, 6))
     res = long_decimal_division(divisor, dividend)
     self.assertEqual(res[3], [6])
     self.assertEqual(res[2], [1])
     self.assertEqual(res[1], multiplier)
     self.assertEqual(res[0], 1)
Exemple #3
0
 def testExact(self, divisor, multiplier):
     """
     A divisor that divides the dividend has no decimal part.
     """
     dividend = Fraction(divisor) * multiplier
     res = long_decimal_division(divisor, dividend)
     self.assertEqual(res[3], [])
     self.assertEqual(res[2], [])
     self.assertEqual(res[1], multiplier)
     self.assertEqual(res[0], 1)
Exemple #4
0
 def testNonRepeatingDecimal(self, divisor, multiplier):
     """
     Should always end in .5.
     """
     dividend = Fraction(divisor) * (multiplier + Fraction(1, 2))
     res = long_decimal_division(divisor, dividend)
     self.assertEqual(res[3], [])
     self.assertEqual(res[2], [5])
     self.assertEqual(res[1], multiplier)
     self.assertEqual(res[0], 1)
Exemple #5
0
 def testException(self):
     """
     Test exceptions.
     """
     with self.assertRaises(SizeValueError):
         long_decimal_division(1.2, 1)
     with self.assertRaises(SizeValueError):
         long_decimal_division(1, 1.2)
     with self.assertRaises(SizeValueError):
         long_decimal_division(0, 1)