summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-24 00:54:21 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-01-24 00:54:21 (GMT)
commitcf10926088c1e8a4f2d3097e095fa0fd7d5d681a (patch)
tree62335adb430d706e1c5cd7b9caae5eb0a08450c2 /Lib/test
parent9acc387bcfca60f4f641f52914e70714034b085c (diff)
downloadcpython-cf10926088c1e8a4f2d3097e095fa0fd7d5d681a.zip
cpython-cf10926088c1e8a4f2d3097e095fa0fd7d5d681a.tar.gz
cpython-cf10926088c1e8a4f2d3097e095fa0fd7d5d681a.tar.bz2
Add first-cut at an approximation function (still needs rounding tweaks). Add continued fraction conversions.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_rational.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_rational.py b/Lib/test/test_rational.py
index 5ee7b7d..76757ba 100644
--- a/Lib/test/test_rational.py
+++ b/Lib/test/test_rational.py
@@ -135,6 +135,18 @@ class RationalTest(unittest.TestCase):
TypeError, "Cannot convert sNaN to Rational.",
R.from_decimal, Decimal("snan"))
+ def testFromContinuedFraction(self):
+ self.assertRaises(TypeError, R.from_continued_fraction, None)
+ phi = R.from_continued_fraction([1]*100)
+ self.assertEquals(round(phi - (1 + 5 ** 0.5) / 2, 10), 0.0)
+
+ def testAsContinuedFraction(self):
+ self.assertEqual(R.from_float(math.pi).as_continued_fraction()[:15],
+ [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
+
+ def testApproximateFromFloat(self):
+ self.assertEqual(R.approximate_from_float(math.pi, 10000), R(355, 113))
+
def testConversions(self):
self.assertTypedEquals(-1, trunc(R(-11, 10)))
self.assertTypedEquals(-2, R(-11, 10).__floor__())