Kaydet (Commit) cf2ce36f authored tarafından Guido van Rossum's avatar Guido van Rossum

Keir Mierle's improved tests for dict view containment tests.

üst 1d719960
...@@ -399,50 +399,52 @@ class DictTest(unittest.TestCase): ...@@ -399,50 +399,52 @@ class DictTest(unittest.TestCase):
self.fail("< didn't raise Exc") self.fail("< didn't raise Exc")
def test_keys_contained(self): 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 # Test rich comparisons against dict key views, which should behave the
# same as sets. # same as sets.
empty = dict() empty = fn(dict())
empty2 = dict() empty2 = fn(dict())
smaller = {1:1, 2:2} smaller = fn({1:1, 2:2})
larger = {1:1, 2:2, 3:3} larger = fn({1:1, 2:2, 3:3})
larger2 = {1:1, 2:2, 3:3} larger2 = fn({1:1, 2:2, 3:3})
larger3 = {4:1, 2:2, 3:3} larger3 = fn({4:1, 2:2, 3:3})
self.assertTrue(smaller.keys() < larger.keys()) self.assertTrue(smaller < larger)
self.assertTrue(smaller.keys() <= larger.keys()) self.assertTrue(smaller <= larger)
self.assertTrue(larger.keys() > smaller.keys()) self.assertTrue(larger > smaller)
self.assertTrue(larger.keys() >= smaller.keys()) self.assertTrue(larger >= smaller)
self.assertFalse(smaller.keys() >= larger.keys()) self.assertFalse(smaller >= larger)
self.assertFalse(smaller.keys() > larger.keys()) self.assertFalse(smaller > larger)
self.assertFalse(larger.keys() <= smaller.keys()) self.assertFalse(larger <= smaller)
self.assertFalse(larger.keys() < smaller.keys()) self.assertFalse(larger < smaller)
self.assertFalse(smaller.keys() < larger3.keys()) self.assertFalse(smaller < larger3)
self.assertFalse(smaller.keys() <= larger3.keys()) self.assertFalse(smaller <= larger3)
self.assertFalse(larger3.keys() > smaller.keys()) self.assertFalse(larger3 > smaller)
self.assertFalse(larger3.keys() >= smaller.keys()) self.assertFalse(larger3 >= smaller)
# Inequality strictness # Inequality strictness
self.assertTrue(larger2.keys() >= larger.keys()) self.assertTrue(larger2 >= larger)
self.assertTrue(larger2.keys() <= larger.keys()) self.assertTrue(larger2 <= larger)
self.assertFalse(larger2.keys() > larger.keys()) self.assertFalse(larger2 > larger)
self.assertFalse(larger2.keys() < larger.keys()) self.assertFalse(larger2 < larger)
self.assertTrue(larger.keys() == larger2.keys()) self.assertTrue(larger == larger2)
self.assertTrue(smaller.keys() != larger.keys()) self.assertTrue(smaller != larger)
# There is an optimization on the zero-element case. # There is an optimization on the zero-element case.
self.assertTrue(empty.keys() == empty2.keys()) self.assertTrue(empty == empty2)
self.assertFalse(empty.keys() != empty2.keys()) self.assertFalse(empty != empty2)
self.assertFalse(empty.keys() == smaller.keys()) self.assertFalse(empty == smaller)
self.assertTrue(empty.keys() != smaller.keys()) self.assertTrue(empty != smaller)
# With the same size, an elementwise compare happens # With the same size, an elementwise compare happens
self.assertTrue(larger.keys() != larger3.keys()) self.assertTrue(larger != larger3)
self.assertFalse(larger.keys() == larger3.keys()) self.assertFalse(larger == larger3)
# XXX the same tests for .items()
def test_errors_in_view_containment_check(self): def test_errors_in_view_containment_check(self):
class C: class C:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment