Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

## Side by Side Diff: Lib/test/test_fractions.py

Issue 7652: Merge C version of decimal into py3k.
Patch Set: Created 7 years, 10 months ago
 Left: Base Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Patch Set 6: None Patch Set 7: None Patch Set 8: None Patch Set 9: None Patch Set 10: None Patch Set 11: None Patch Set 12: None Right: Patch Set 1: None Patch Set 2: None Patch Set 3: None Patch Set 4: None Patch Set 5: None Patch Set 6: None Patch Set 7: None Patch Set 8: None Patch Set 9: None Patch Set 10: None Patch Set 11: None Patch Set 12: None
« no previous file with comments | « Lib/test/test_decimal.py ('k') | Lib/test/test_numeric_tower.py » ('j') | no next file with comments »
OLDNEW
1 """Tests for Lib/fractions.py.""" 1 """Tests for Lib/fractions.py."""
2 2
3 from decimal import Decimal 3 from decimal import Decimal
4 from test.support import run_unittest, requires_IEEE_754 4 from test.support import run_unittest, requires_IEEE_754
5 import math 5 import math
6 import numbers 6 import numbers
7 import operator 7 import operator
8 import fractions 8 import fractions
9 import sys 9 import sys
10 import unittest 10 import unittest
(...skipping 383 matching lines...)
394 z = pow(-1, F(1, 2)) 394 z = pow(-1, F(1, 2))
395 self.assertAlmostEqual(0, z.real) 395 self.assertAlmostEqual(0, z.real)
396 self.assertEqual(1, z.imag) 396 self.assertEqual(1, z.imag)
397 self.assertTypedEquals(F(1, 4) , 2 ** F(-2, 1)) 397 self.assertTypedEquals(F(1, 4) , 2 ** F(-2, 1))
398 self.assertTypedEquals(2.0 , 4 ** F(1, 2)) 398 self.assertTypedEquals(2.0 , 4 ** F(1, 2))
399 self.assertTypedEquals(0.25, 2.0 ** F(-2, 1)) 399 self.assertTypedEquals(0.25, 2.0 ** F(-2, 1))
400 self.assertTypedEquals(1.0 + 0j, (1.0 + 0j) ** F(1, 10)) 400 self.assertTypedEquals(1.0 + 0j, (1.0 + 0j) ** F(1, 10))
401 401
402 def testMixingWithDecimal(self): 402 def testMixingWithDecimal(self):
403 # Decimal refuses mixed arithmetic (but not mixed comparisons) 403 # Decimal refuses mixed arithmetic (but not mixed comparisons)
405 TypeError, 405 F(3,11), Decimal('3.1415926'))
406 "unsupported operand type(s) for +: 'Fraction' and 'Decimal'", 406 self.assertRaises(TypeError, operator.add,
407 operator.add, F(3,11), Decimal('3.1415926')) 407 Decimal('3.1415926'), F(3,11))
408 self.assertRaisesMessage(
409 TypeError,
410 "unsupported operand type(s) for +: 'Decimal' and 'Fraction'",
412 408
413 def testComparisons(self): 409 def testComparisons(self):
414 self.assertTrue(F(1, 2) < F(2, 3)) 410 self.assertTrue(F(1, 2) < F(2, 3))
415 self.assertFalse(F(1, 2) < F(1, 2)) 411 self.assertFalse(F(1, 2) < F(1, 2))
416 self.assertTrue(F(1, 2) <= F(2, 3)) 412 self.assertTrue(F(1, 2) <= F(2, 3))
417 self.assertTrue(F(1, 2) <= F(1, 2)) 413 self.assertTrue(F(1, 2) <= F(1, 2))
418 self.assertFalse(F(2, 3) <= F(1, 2)) 414 self.assertFalse(F(2, 3) <= F(1, 2))
419 self.assertTrue(F(1, 2) == F(1, 2)) 415 self.assertTrue(F(1, 2) == F(1, 2))
420 self.assertFalse(F(1, 2) == F(1, 3)) 416 self.assertFalse(F(1, 2) == F(1, 3))
421 self.assertFalse(F(1, 2) != F(1, 2)) 417 self.assertFalse(F(1, 2) != F(1, 2))
(...skipping 181 matching lines...)
603 def test_slots(self): 599 def test_slots(self):
604 # Issue 4998 600 # Issue 4998
605 r = F(13, 7) 601 r = F(13, 7)
606 self.assertRaises(AttributeError, setattr, r, 'a', 10) 602 self.assertRaises(AttributeError, setattr, r, 'a', 10)
607 603
608 def test_main(): 604 def test_main():
609 run_unittest(FractionTest, GcdTest) 605 run_unittest(FractionTest, GcdTest)
610 606
611 if __name__ == '__main__': 607 if __name__ == '__main__':
612 test_main() 608 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_decimal.py ('k') | Lib/test/test_numeric_tower.py » ('j') | no next file with comments »

This is Rietveld 894c83f36cb7+