diff options
author | Guido van Rossum <guido@python.org> | 2007-08-24 23:49:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-24 23:49:54 (GMT) |
commit | cf2ce36fa28d732cd3ccdfd7a747dfb518d0bfee (patch) | |
tree | 82326cc5c2f7515ed40bd4e0d011a0c2abb39c60 | |
parent | 1d719960131b1d288085c5d2df6d7d2dfbdfb54e (diff) | |
download | cpython-cf2ce36fa28d732cd3ccdfd7a747dfb518d0bfee.zip cpython-cf2ce36fa28d732cd3ccdfd7a747dfb518d0bfee.tar.gz cpython-cf2ce36fa28d732cd3ccdfd7a747dfb518d0bfee.tar.bz2 |
Keir Mierle's improved tests for dict view containment tests.
-rw-r--r-- | Lib/test/test_dict.py | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index a9e4156..27bda3f 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -399,50 +399,52 @@ class DictTest(unittest.TestCase): self.fail("< didn't raise Exc") def test_keys_contained(self): + self.helper_keys_contained(lambda x: x.keys()) + self.helper_keys_contained(lambda x: x.items()) + + def helper_keys_contained(self, fn): # Test rich comparisons against dict key views, which should behave the # same as sets. - empty = dict() - empty2 = dict() - smaller = {1:1, 2:2} - larger = {1:1, 2:2, 3:3} - larger2 = {1:1, 2:2, 3:3} - larger3 = {4:1, 2:2, 3:3} - - self.assertTrue(smaller.keys() < larger.keys()) - self.assertTrue(smaller.keys() <= larger.keys()) - self.assertTrue(larger.keys() > smaller.keys()) - self.assertTrue(larger.keys() >= smaller.keys()) - - self.assertFalse(smaller.keys() >= larger.keys()) - self.assertFalse(smaller.keys() > larger.keys()) - self.assertFalse(larger.keys() <= smaller.keys()) - self.assertFalse(larger.keys() < smaller.keys()) - - self.assertFalse(smaller.keys() < larger3.keys()) - self.assertFalse(smaller.keys() <= larger3.keys()) - self.assertFalse(larger3.keys() > smaller.keys()) - self.assertFalse(larger3.keys() >= smaller.keys()) + empty = fn(dict()) + empty2 = fn(dict()) + smaller = fn({1:1, 2:2}) + larger = fn({1:1, 2:2, 3:3}) + larger2 = fn({1:1, 2:2, 3:3}) + larger3 = fn({4:1, 2:2, 3:3}) + + self.assertTrue(smaller < larger) + self.assertTrue(smaller <= larger) + self.assertTrue(larger > smaller) + self.assertTrue(larger >= smaller) + + self.assertFalse(smaller >= larger) + self.assertFalse(smaller > larger) + self.assertFalse(larger <= smaller) + self.assertFalse(larger < smaller) + + self.assertFalse(smaller < larger3) + self.assertFalse(smaller <= larger3) + self.assertFalse(larger3 > smaller) + self.assertFalse(larger3 >= smaller) # Inequality strictness - self.assertTrue(larger2.keys() >= larger.keys()) - self.assertTrue(larger2.keys() <= larger.keys()) - self.assertFalse(larger2.keys() > larger.keys()) - self.assertFalse(larger2.keys() < larger.keys()) + self.assertTrue(larger2 >= larger) + self.assertTrue(larger2 <= larger) + self.assertFalse(larger2 > larger) + self.assertFalse(larger2 < larger) - self.assertTrue(larger.keys() == larger2.keys()) - self.assertTrue(smaller.keys() != larger.keys()) + self.assertTrue(larger == larger2) + self.assertTrue(smaller != larger) # There is an optimization on the zero-element case. - self.assertTrue(empty.keys() == empty2.keys()) - self.assertFalse(empty.keys() != empty2.keys()) - self.assertFalse(empty.keys() == smaller.keys()) - self.assertTrue(empty.keys() != smaller.keys()) + self.assertTrue(empty == empty2) + self.assertFalse(empty != empty2) + self.assertFalse(empty == smaller) + self.assertTrue(empty != smaller) # With the same size, an elementwise compare happens - self.assertTrue(larger.keys() != larger3.keys()) - self.assertFalse(larger.keys() == larger3.keys()) - - # XXX the same tests for .items() + self.assertTrue(larger != larger3) + self.assertFalse(larger == larger3) def test_errors_in_view_containment_check(self): class C: |