aboutsummaryrefslogtreecommitdiffstats
path: root/unittest/rational.py
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/rational.py')
-rw-r--r--unittest/rational.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/unittest/rational.py b/unittest/rational.py
index 8ae6d65..f475846 100644
--- a/unittest/rational.py
+++ b/unittest/rational.py
@@ -36,6 +36,14 @@ class TestRational(unittest.TestCase):
self.assertEqual(r.denominator, 1)
self.assertRaises(ZeroDivisionError, Rational, 1, 0)
+ def test_from_string(self):
+ self.assertEqual(Rational.from_string('4/3'), Rational(4, 3))
+ self.assertEqual(Rational.from_string('-4/3'), Rational(-4, 3))
+ self.assertRaises(ValueError, Rational.from_string, '+3/5')
+ self.assertRaises(ValueError, Rational.from_string, '3 / 5')
+ self.assertRaises(ValueError, Rational.from_string, '3/-5')
+ self.assertRaises(ValueError, Rational.from_string, 'invalid')
+
def test_equality(self):
r1 = Rational(2, 1)
r2 = Rational(2, 1)