diff options
Diffstat (limited to 'Lib/test/test_rational.py')
-rw-r--r-- | Lib/test/test_rational.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_rational.py b/Lib/test/test_rational.py index 1bd1814..49868dd 100644 --- a/Lib/test/test_rational.py +++ b/Lib/test/test_rational.py @@ -6,6 +6,8 @@ import math import operator import rational import unittest +from copy import copy, deepcopy +from cPickle import dumps, loads R = rational.Rational def _components(r): @@ -153,16 +155,17 @@ class RationalTest(unittest.TestCase): [-4, 1, 6, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3]) self.assertEqual(R(0).as_continued_fraction(), [0]) - def testApproximateFromFloat(self): - self.assertEqual(R.approximate_from_float(math.pi, 10000), R(355, 113)) - self.assertEqual(R.approximate_from_float(-math.pi, 10000), R(-355, 113)) - self.assertEqual(R.approximate_from_float(0.0, 10000), R(0)) + def testApproximateFrom(self): + self.assertEqual(R.from_float(math.pi).approximate(10000), R(355, 113)) + self.assertEqual(R.from_float(-math.pi).approximate(10000), R(-355, 113)) + self.assertEqual(R.from_float(0.0).approximate(10000), R(0)) def testConversions(self): self.assertTypedEquals(-1, trunc(R(-11, 10))) self.assertTypedEquals(-2, math.floor(R(-11, 10))) self.assertTypedEquals(-1, math.ceil(R(-11, 10))) self.assertTypedEquals(-1, math.ceil(R(-10, 10))) + self.assertTypedEquals(-1, int(R(-11, 10))) self.assertTypedEquals(0, round(R(-1, 10))) self.assertTypedEquals(0, round(R(-5, 10))) @@ -360,6 +363,12 @@ class RationalTest(unittest.TestCase): s += num / fact * sign self.assertAlmostEquals(math.cos(1), s) + def test_copy_deepcopy_pickle(self): + r = R(13, 7) + self.assertEqual(r, loads(dumps(r))) + self.assertEqual(id(r), id(copy(r))) + self.assertEqual(id(r), id(deepcopy(r))) + def test_main(): run_unittest(RationalTest) |