Back to index

python3.2  3.2.2
Public Member Functions
test.test_numeric_tower.ComparisonTest Class Reference

List of all members.

Public Member Functions

def test_mixed_comparisons
def test_complex

Detailed Description

Definition at line 146 of file test_numeric_tower.py.


Member Function Documentation

Definition at line 178 of file test_numeric_tower.py.

00178 
00179     def test_complex(self):
00180         # comparisons with complex are special:  equality and inequality
00181         # comparisons should always succeed, but order comparisons should
00182         # raise TypeError.
00183         z = 1.0 + 0j
00184         w = -3.14 + 2.7j
00185 
00186         for v in 1, 1.0, F(1), D(1), complex(1):
00187             self.assertEqual(z, v)
00188             self.assertEqual(v, z)
00189 
00190         for v in 2, 2.0, F(2), D(2), complex(2):
00191             self.assertNotEqual(z, v)
00192             self.assertNotEqual(v, z)
00193             self.assertNotEqual(w, v)
00194             self.assertNotEqual(v, w)
00195 
00196         for v in (1, 1.0, F(1), D(1), complex(1),
00197                   2, 2.0, F(2), D(2), complex(2), w):
00198             for op in operator.le, operator.lt, operator.ge, operator.gt:
00199                 self.assertRaises(TypeError, op, z, v)
00200                 self.assertRaises(TypeError, op, v, z)
00201 

Here is the call graph for this function:

Definition at line 147 of file test_numeric_tower.py.

00147 
00148     def test_mixed_comparisons(self):
00149 
00150         # ordered list of distinct test values of various types:
00151         # int, float, Fraction, Decimal
00152         test_values = [
00153             float('-inf'),
00154             D('-1e999999999'),
00155             -1e308,
00156             F(-22, 7),
00157             -3.14,
00158             -2,
00159             0.0,
00160             1e-320,
00161             True,
00162             F('1.2'),
00163             D('1.3'),
00164             float('1.4'),
00165             F(275807, 195025),
00166             D('1.414213562373095048801688724'),
00167             F(114243, 80782),
00168             F(473596569, 84615),
00169             7e200,
00170             D('infinity'),
00171             ]
00172         for i, first in enumerate(test_values):
00173             for second in test_values[i+1:]:
00174                 self.assertLess(first, second)
00175                 self.assertLessEqual(first, second)
00176                 self.assertGreater(second, first)
00177                 self.assertGreaterEqual(second, first)

Here is the call graph for this function:


The documentation for this class was generated from the following file: