Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_sets.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
3 import unittest, operator, copy, pickle, random |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
4 from test import test_support |
|
40614
b303fb383fa4
Deprecate the sets module.
Brett Cannon <bcannon@gmail.com>
parents:
37408
diff
changeset
|
5 |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
6 test_support.import_module("sets", deprecated=True) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 from sets import Set, ImmutableSet |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 empty_set = Set() |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 class TestBasicOps(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 def test_repr(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 if self.repr is not None: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
30533
diff
changeset
|
17 self.assertEqual(repr(self.set), self.repr) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 def test_length(self): |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
20 self.assertEqual(len(self.set), self.length) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 def test_self_equality(self): |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
23 self.assertEqual(self.set, self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 def test_equivalent_equality(self): |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
26 self.assertEqual(self.set, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 def test_copy(self): |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
29 self.assertEqual(self.set.copy(), self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 def test_self_union(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 result = self.set | self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
33 self.assertEqual(result, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 def test_empty_union(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 result = self.set | empty_set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
37 self.assertEqual(result, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 def test_union_empty(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 result = empty_set | self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
41 self.assertEqual(result, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 def test_self_intersection(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 result = self.set & self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
45 self.assertEqual(result, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 def test_empty_intersection(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 result = self.set & empty_set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
49 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 def test_intersection_empty(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 result = empty_set & self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
53 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 def test_self_symmetric_difference(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 result = self.set ^ self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
57 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 def checkempty_symmetric_difference(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 result = self.set ^ empty_set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
61 self.assertEqual(result, self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 def test_self_difference(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 result = self.set - self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
65 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 def test_empty_difference(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 result = self.set - empty_set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
69 self.assertEqual(result, self.dup) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 def test_empty_difference_rev(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 result = empty_set - self.set |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
73 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 def test_iteration(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 for v in self.set: |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
77 self.assertIn(v, self.values) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
26197
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
79 def test_pickling(self): |
|
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
80 p = pickle.dumps(self.set) |
|
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
81 copy = pickle.loads(p) |
|
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
82 self.assertEqual(self.set, copy, |
|
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
83 "%s != %s" % (self.set, copy)) |
|
cb71e7c620e2
Add getstate and setstate implementation to concrete set classes.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
26128
diff
changeset
|
84 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 class TestBasicOpsEmpty(TestBasicOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 self.case = "empty set" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 self.values = [] |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 self.set = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 self.dup = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 self.length = 0 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 self.repr = "Set([])" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 class TestBasicOpsSingleton(TestBasicOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 self.case = "unit set (number)" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 self.values = [3] |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 self.set = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 self.dup = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 self.length = 1 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 self.repr = "Set([3])" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 def test_in(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
108 self.assertTrue(3 in self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 def test_not_in(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
111 self.assertTrue(2 not in self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 class TestBasicOpsTuple(TestBasicOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 self.case = "unit set (tuple)" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 self.values = [(0, "zero")] |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 self.set = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 self.dup = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 self.length = 1 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 self.repr = "Set([(0, 'zero')])" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 def test_in(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
125 self.assertTrue((0, "zero") in self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 def test_not_in(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
128 self.assertTrue(9 not in self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 class TestBasicOpsTriple(TestBasicOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 self.case = "triple set" |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 self.values = [0, "zero", operator.add] |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 self.set = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 self.dup = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 self.length = 3 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 self.repr = None |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 |
|
26101
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
143 def baditer(): |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
144 raise TypeError |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
145 yield True |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
146 |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
147 def gooditer(): |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
148 yield True |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
149 |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
150 class TestExceptionPropagation(unittest.TestCase): |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
151 """SF 628246: Set constructor should not trap iterator TypeErrors""" |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
152 |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
153 def test_instanceWithException(self): |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
154 self.assertRaises(TypeError, Set, baditer()) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
155 |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
156 def test_instancesWithoutException(self): |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
157 # All of these iterables should load without exception. |
|
26101
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
158 Set([1,2,3]) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
159 Set((1,2,3)) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
160 Set({'one':1, 'two':2, 'three':3}) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
161 Set(xrange(3)) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
162 Set('abc') |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
163 Set(gooditer()) |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
164 |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
165 #============================================================================== |
|
0820ad49829d
Closes SF bug #628246.
Raymond Hettinger <python@rcn.com>
parents:
25031
diff
changeset
|
166 |
|
24933
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
167 class TestSetOfSets(unittest.TestCase): |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
168 def test_constructor(self): |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
169 inner = Set([1]) |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
170 outer = Set([inner]) |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
171 element = outer.pop() |
|
25029
aff067ba8d07
Rewrote all remaining assert stmts.
Tim Peters <tim.peters@gmail.com>
parents:
25028
diff
changeset
|
172 self.assertEqual(type(element), ImmutableSet) |
|
25011
f36e16ca8f50
Expanded tests for sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24933
diff
changeset
|
173 outer.add(inner) # Rebuild set of sets with .add method |
|
f36e16ca8f50
Expanded tests for sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24933
diff
changeset
|
174 outer.remove(inner) |
|
25029
aff067ba8d07
Rewrote all remaining assert stmts.
Tim Peters <tim.peters@gmail.com>
parents:
25028
diff
changeset
|
175 self.assertEqual(outer, Set()) # Verify that remove worked |
|
25011
f36e16ca8f50
Expanded tests for sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24933
diff
changeset
|
176 outer.discard(inner) # Absence of KeyError indicates working fine |
|
24933
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
177 |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
178 #============================================================================== |
|
9ee4f4cb9770
Add regression test for proper construction of sets of sets.
Raymond Hettinger <python@rcn.com>
parents:
24924
diff
changeset
|
179 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 class TestBinaryOps(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 self.set = Set((2, 4, 6)) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 |
|
26408
3fa6ded0a1e9
SF 643115: Set._update() had a special case for dictionaries which allowed
Raymond Hettinger <python@rcn.com>
parents:
26200
diff
changeset
|
184 def test_eq(self): # SF bug 643115 |
|
3fa6ded0a1e9
SF 643115: Set._update() had a special case for dictionaries which allowed
Raymond Hettinger <python@rcn.com>
parents:
26200
diff
changeset
|
185 self.assertEqual(self.set, Set({2:1,4:3,6:5})) |
|
3fa6ded0a1e9
SF 643115: Set._update() had a special case for dictionaries which allowed
Raymond Hettinger <python@rcn.com>
parents:
26200
diff
changeset
|
186 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 def test_union_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 result = self.set | Set([2]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
189 self.assertEqual(result, Set((2, 4, 6))) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 def test_union_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 result = self.set | Set([2, 4, 6, 8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
193 self.assertEqual(result, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 def test_union_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 result = self.set | Set([3, 4, 5]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
197 self.assertEqual(result, Set([2, 3, 4, 5, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 def test_union_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 result = self.set | Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
201 self.assertEqual(result, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 def test_intersection_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 result = self.set & Set((2, 4)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
205 self.assertEqual(result, Set((2, 4))) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 def test_intersection_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 result = self.set & Set([2, 4, 6, 8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
209 self.assertEqual(result, Set([2, 4, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 def test_intersection_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 result = self.set & Set([3, 4, 5]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
213 self.assertEqual(result, Set([4])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 def test_intersection_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 result = self.set & Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
217 self.assertEqual(result, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 def test_sym_difference_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 result = self.set ^ Set((2, 4)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
221 self.assertEqual(result, Set([6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 def test_sym_difference_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 result = self.set ^ Set((2, 4, 6, 8)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
225 self.assertEqual(result, Set([8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 def test_sym_difference_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 result = self.set ^ Set((3, 4, 5)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
229 self.assertEqual(result, Set([2, 3, 5, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 def test_sym_difference_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 result = self.set ^ Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
233 self.assertEqual(result, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
235 def test_cmp(self): |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
236 a, b = Set('a'), Set('b') |
|
28127
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
237 self.assertRaises(TypeError, cmp, a, b) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
238 |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
239 # You can view this as a buglet: cmp(a, a) does not raise TypeError, |
|
28128
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
240 # because __eq__ is tried before __cmp__, and a.__eq__(a) returns True, |
|
28127
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
241 # which Python thinks is good enough to synthesize a cmp() result |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
242 # without calling __cmp__. |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
243 self.assertEqual(cmp(a, a), 0) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
244 |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
245 self.assertRaises(TypeError, cmp, a, 12) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
246 self.assertRaises(TypeError, cmp, "abc", a) |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
247 |
|
35337
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
248 def test_inplace_on_self(self): |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
249 t = self.set.copy() |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
250 t |= t |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
251 self.assertEqual(t, self.set) |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
252 t &= t |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
253 self.assertEqual(t, self.set) |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
254 t -= t |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
255 self.assertEqual(len(t), 0) |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
256 t = self.set.copy() |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
257 t ^= t |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
258 self.assertEqual(len(t), 0) |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
259 |
|
def434e2a81a
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
Raymond Hettinger <python@rcn.com>
parents:
32984
diff
changeset
|
260 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 class TestUpdateOps(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 self.set = Set((2, 4, 6)) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 def test_union_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 self.set |= Set([2]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
269 self.assertEqual(self.set, Set((2, 4, 6))) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 def test_union_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 self.set |= Set([2, 4, 6, 8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
273 self.assertEqual(self.set, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 def test_union_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 self.set |= Set([3, 4, 5]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
277 self.assertEqual(self.set, Set([2, 3, 4, 5, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 def test_union_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 self.set |= Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
281 self.assertEqual(self.set, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
283 def test_union_method_call(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
284 self.set.union_update(Set([3, 4, 5])) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
285 self.assertEqual(self.set, Set([2, 3, 4, 5, 6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
286 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 def test_intersection_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 self.set &= Set((2, 4)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
289 self.assertEqual(self.set, Set((2, 4))) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 def test_intersection_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 self.set &= Set([2, 4, 6, 8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
293 self.assertEqual(self.set, Set([2, 4, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 def test_intersection_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 self.set &= Set([3, 4, 5]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
297 self.assertEqual(self.set, Set([4])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 def test_intersection_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 self.set &= Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
301 self.assertEqual(self.set, empty_set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
303 def test_intersection_method_call(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
304 self.set.intersection_update(Set([3, 4, 5])) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
305 self.assertEqual(self.set, Set([4])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
306 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 def test_sym_difference_subset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 self.set ^= Set((2, 4)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
309 self.assertEqual(self.set, Set([6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 def test_sym_difference_superset(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 self.set ^= Set((2, 4, 6, 8)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
313 self.assertEqual(self.set, Set([8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 def test_sym_difference_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 self.set ^= Set((3, 4, 5)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
317 self.assertEqual(self.set, Set([2, 3, 5, 6])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 def test_sym_difference_non_overlap(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 self.set ^= Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
321 self.assertEqual(self.set, Set([2, 4, 6, 8])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
323 def test_sym_difference_method_call(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
324 self.set.symmetric_difference_update(Set([3, 4, 5])) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
325 self.assertEqual(self.set, Set([2, 3, 5, 6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
326 |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
327 def test_difference_subset(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
328 self.set -= Set((2, 4)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
329 self.assertEqual(self.set, Set([6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
330 |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
331 def test_difference_superset(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
332 self.set -= Set((2, 4, 6, 8)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
333 self.assertEqual(self.set, Set([])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
334 |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
335 def test_difference_overlap(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
336 self.set -= Set((3, 4, 5)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
337 self.assertEqual(self.set, Set([2, 6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
338 |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
339 def test_difference_non_overlap(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
340 self.set -= Set([8]) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
341 self.assertEqual(self.set, Set([2, 4, 6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
342 |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
343 def test_difference_method_call(self): |
|
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
344 self.set.difference_update(Set([3, 4, 5])) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
345 self.assertEqual(self.set, Set([2, 6])) |
|
25014
feeb0b02b8f2
At Tim Peter's suggestion, propagated GvR's binary operator changes to
Raymond Hettinger <python@rcn.com>
parents:
25011
diff
changeset
|
346 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 class TestMutate(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 self.values = ["a", "b", "c"] |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 self.set = Set(self.values) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 def test_add_present(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 self.set.add("c") |
|
25027
3484309573f2
Simplified code building sets of characters.
Tim Peters <tim.peters@gmail.com>
parents:
25026
diff
changeset
|
356 self.assertEqual(self.set, Set("abc")) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 def test_add_absent(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 self.set.add("d") |
|
25027
3484309573f2
Simplified code building sets of characters.
Tim Peters <tim.peters@gmail.com>
parents:
25026
diff
changeset
|
360 self.assertEqual(self.set, Set("abcd")) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 def test_add_until_full(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 tmp = Set() |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 expected_len = 0 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 for v in self.values: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 tmp.add(v) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 expected_len += 1 |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
368 self.assertEqual(len(tmp), expected_len) |
|
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
369 self.assertEqual(tmp, self.set) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 def test_remove_present(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 self.set.remove("b") |
|
25027
3484309573f2
Simplified code building sets of characters.
Tim Peters <tim.peters@gmail.com>
parents:
25026
diff
changeset
|
373 self.assertEqual(self.set, Set("ac")) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 def test_remove_absent(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 try: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 self.set.remove("d") |
|
25029
aff067ba8d07
Rewrote all remaining assert stmts.
Tim Peters <tim.peters@gmail.com>
parents:
25028
diff
changeset
|
378 self.fail("Removing missing element should have raised LookupError") |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 except LookupError: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 pass |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 def test_remove_until_empty(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 expected_len = len(self.set) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 for v in self.values: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 self.set.remove(v) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 expected_len -= 1 |
|
25029
aff067ba8d07
Rewrote all remaining assert stmts.
Tim Peters <tim.peters@gmail.com>
parents:
25028
diff
changeset
|
387 self.assertEqual(len(self.set), expected_len) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 def test_discard_present(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 self.set.discard("c") |
|
25027
3484309573f2
Simplified code building sets of characters.
Tim Peters <tim.peters@gmail.com>
parents:
25026
diff
changeset
|
391 self.assertEqual(self.set, Set("ab")) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 def test_discard_absent(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 self.set.discard("d") |
|
25027
3484309573f2
Simplified code building sets of characters.
Tim Peters <tim.peters@gmail.com>
parents:
25026
diff
changeset
|
395 self.assertEqual(self.set, Set("abc")) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 def test_clear(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 self.set.clear() |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
399 self.assertEqual(len(self.set), 0) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 |
|
24924
a1143224ee0d
Rename popitem() to pop(). (An idea from SF patch 597444.)
Guido van Rossum <guido@python.org>
parents:
24891
diff
changeset
|
401 def test_pop(self): |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 popped = {} |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 while self.set: |
|
24924
a1143224ee0d
Rename popitem() to pop(). (An idea from SF patch 597444.)
Guido van Rossum <guido@python.org>
parents:
24891
diff
changeset
|
404 popped[self.set.pop()] = None |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
405 self.assertEqual(len(popped), len(self.values)) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 for v in self.values: |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
407 self.assertIn(v, popped) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 def test_update_empty_tuple(self): |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
410 self.set.union_update(()) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
411 self.assertEqual(self.set, Set(self.values)) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 def test_update_unit_tuple_overlap(self): |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
414 self.set.union_update(("a",)) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
415 self.assertEqual(self.set, Set(self.values)) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 def test_update_unit_tuple_non_overlap(self): |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
418 self.set.union_update(("a", "z")) |
|
25026
2c2b84bda141
Ack! Virtually every test here relied on an assert stmt. assert stmts
Tim Peters <tim.peters@gmail.com>
parents:
25025
diff
changeset
|
419 self.assertEqual(self.set, Set(self.values + ["z"])) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 class TestSubsets(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
425 case2method = {"<=": "issubset", |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
426 ">=": "issuperset", |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
427 } |
|
25031
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
428 |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
429 reverse = {"==": "==", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
430 "!=": "!=", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
431 "<": ">", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
432 ">": "<", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
433 "<=": ">=", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
434 ">=": "<=", |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
435 } |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
436 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 def test_issubset(self): |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
438 x = self.left |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
439 y = self.right |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
440 for case in "!=", "==", "<", "<=", ">", ">=": |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
441 expected = case in self.cases |
|
25031
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
442 # Test the binary infix spelling. |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
443 result = eval("x" + case + "y", locals()) |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
444 self.assertEqual(result, expected) |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
445 # Test the "friendly" method-name spelling, if one exists. |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
446 if case in TestSubsets.case2method: |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
447 method = getattr(x, TestSubsets.case2method[case]) |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
448 result = method(y) |
|
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
449 self.assertEqual(result, expected) |
|
25031
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
450 |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
451 # Now do the same for the operands reversed. |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
452 rcase = TestSubsets.reverse[case] |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
453 result = eval("y" + rcase + "x", locals()) |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
454 self.assertEqual(result, expected) |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
455 if rcase in TestSubsets.case2method: |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
456 method = getattr(y, TestSubsets.case2method[rcase]) |
|
40e9cfde1c50
Implemented <, <=, >, >= for sets, giving subset and proper-subset
Tim Peters <tim.peters@gmail.com>
parents:
25030
diff
changeset
|
457 result = method(x) |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
458 self.assertEqual(result, expected) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 class TestSubsetEqualEmpty(TestSubsets): |
|
25025
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
462 left = Set() |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
463 right = Set() |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
464 name = "both empty" |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
465 cases = "==", "<=", ">=" |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 class TestSubsetEqualNonEmpty(TestSubsets): |
|
25025
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
470 left = Set([1, 2]) |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
471 right = Set([1, 2]) |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
472 name = "equal pair" |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
473 cases = "==", "<=", ">=" |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 class TestSubsetEmptyNonEmpty(TestSubsets): |
|
25025
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
478 left = Set() |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
479 right = Set([1, 2]) |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
480 name = "one empty, one non-empty" |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
481 cases = "!=", "<", "<=" |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
485 class TestSubsetPartial(TestSubsets): |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
26101
diff
changeset
|
486 left = Set([1]) |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
26101
diff
changeset
|
487 right = Set([1, 2]) |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
26101
diff
changeset
|
488 name = "one a non-empty proper subset of other" |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
26101
diff
changeset
|
489 cases = "!=", "<", "<=" |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 class TestSubsetNonOverlap(TestSubsets): |
|
25025
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
494 left = Set([1]) |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
495 right = Set([2]) |
|
8fa753a97077
Simplified the setup for is-subset testing.
Tim Peters <tim.peters@gmail.com>
parents:
25018
diff
changeset
|
496 name = "neither empty, neither contains" |
|
25030
8c61c92025b6
TestSubset(): Generalized the framework to support testing upcoming
Tim Peters <tim.peters@gmail.com>
parents:
25029
diff
changeset
|
497 cases = "!=" |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 class TestOnlySetsInBinaryOps(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 |
|
28127
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
503 def test_eq_ne(self): |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
504 # Unlike the others, this is testing that == and != *are* allowed. |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
505 self.assertEqual(self.other == self.set, False) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
506 self.assertEqual(self.set == self.other, False) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
507 self.assertEqual(self.other != self.set, True) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
508 self.assertEqual(self.set != self.other, True) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
509 |
|
28128
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
510 def test_ge_gt_le_lt(self): |
|
28127
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
511 self.assertRaises(TypeError, lambda: self.set < self.other) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
512 self.assertRaises(TypeError, lambda: self.set <= self.other) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
513 self.assertRaises(TypeError, lambda: self.set > self.other) |
|
5f923165319d
SF bug 693121: Set == non-Set is a TypeError.
Tim Peters <tim.peters@gmail.com>
parents:
28126
diff
changeset
|
514 self.assertRaises(TypeError, lambda: self.set >= self.other) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 |
|
28128
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
516 self.assertRaises(TypeError, lambda: self.other < self.set) |
|
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
517 self.assertRaises(TypeError, lambda: self.other <= self.set) |
|
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
518 self.assertRaises(TypeError, lambda: self.other > self.set) |
|
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
519 self.assertRaises(TypeError, lambda: self.other >= self.set) |
|
87913529f248
Typo repairs in new code.
Tim Peters <tim.peters@gmail.com>
parents:
28127
diff
changeset
|
520 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
521 def test_union_update_operator(self): |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 try: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 self.set |= self.other |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 except TypeError: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 pass |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
526 else: |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
527 self.fail("expected TypeError") |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
529 def test_union_update(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
530 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
531 self.set.union_update(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
532 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
533 self.assertRaises(TypeError, self.set.union_update, self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
534 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 def test_union(self): |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
536 self.assertRaises(TypeError, lambda: self.set | self.other) |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
537 self.assertRaises(TypeError, lambda: self.other | self.set) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
538 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
539 self.set.union(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
540 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
541 self.assertRaises(TypeError, self.set.union, self.other) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
542 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
543 def test_intersection_update_operator(self): |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 try: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 self.set &= self.other |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
546 except TypeError: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 pass |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
548 else: |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
549 self.fail("expected TypeError") |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
551 def test_intersection_update(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
552 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
553 self.set.intersection_update(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
554 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
555 self.assertRaises(TypeError, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
556 self.set.intersection_update, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
557 self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
558 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
559 def test_intersection(self): |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
560 self.assertRaises(TypeError, lambda: self.set & self.other) |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
561 self.assertRaises(TypeError, lambda: self.other & self.set) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
562 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
563 self.set.intersection(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
564 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
565 self.assertRaises(TypeError, self.set.intersection, self.other) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
567 def test_sym_difference_update_operator(self): |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 try: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
569 self.set ^= self.other |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
570 except TypeError: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 pass |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
572 else: |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
573 self.fail("expected TypeError") |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
574 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
575 def test_sym_difference_update(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
576 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
577 self.set.symmetric_difference_update(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
578 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
579 self.assertRaises(TypeError, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
580 self.set.symmetric_difference_update, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
581 self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
582 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 def test_sym_difference(self): |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
584 self.assertRaises(TypeError, lambda: self.set ^ self.other) |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
585 self.assertRaises(TypeError, lambda: self.other ^ self.set) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
586 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
587 self.set.symmetric_difference(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
588 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
589 self.assertRaises(TypeError, self.set.symmetric_difference, self.other) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
591 def test_difference_update_operator(self): |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 try: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 self.set -= self.other |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 except TypeError: |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 pass |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
596 else: |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
597 self.fail("expected TypeError") |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
598 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
599 def test_difference_update(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
600 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
601 self.set.difference_update(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
602 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
603 self.assertRaises(TypeError, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
604 self.set.difference_update, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
605 self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
606 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 def test_difference(self): |
|
28129
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
608 self.assertRaises(TypeError, lambda: self.set - self.other) |
|
a24aabcf5ea2
TestOnlySetsInBinaryOps: Simplified the non-inplace tests by using
Tim Peters <tim.peters@gmail.com>
parents:
28128
diff
changeset
|
609 self.assertRaises(TypeError, lambda: self.other - self.set) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
610 if self.otherIsIterable: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
611 self.set.difference(self.other) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
612 else: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
613 self.assertRaises(TypeError, self.set.difference, self.other) |
|
30247
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
614 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 class TestOnlySetsNumeric(TestOnlySetsInBinaryOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 self.set = Set((1, 2, 3)) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 self.other = 19 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
621 self.otherIsIterable = False |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 class TestOnlySetsDict(TestOnlySetsInBinaryOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 self.set = Set((1, 2, 3)) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 self.other = {1:2, 3:4} |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
629 self.otherIsIterable = True |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 class TestOnlySetsOperator(TestOnlySetsInBinaryOps): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 self.set = Set((1, 2, 3)) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 self.other = operator.add |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
637 self.otherIsIterable = False |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
638 |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
639 def test_ge_gt_le_lt(self): |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58460
diff
changeset
|
640 with test_support.check_py3k_warnings(): |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
641 super(TestOnlySetsOperator, self).test_ge_gt_le_lt() |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
642 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
643 #------------------------------------------------------------------------------ |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
644 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
645 class TestOnlySetsTuple(TestOnlySetsInBinaryOps): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
646 def setUp(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
647 self.set = Set((1, 2, 3)) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
648 self.other = (2, 4, 6) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
649 self.otherIsIterable = True |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
650 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
651 #------------------------------------------------------------------------------ |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
652 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
653 class TestOnlySetsString(TestOnlySetsInBinaryOps): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
654 def setUp(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
655 self.set = Set((1, 2, 3)) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
656 self.other = 'abc' |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
657 self.otherIsIterable = True |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
658 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
659 #------------------------------------------------------------------------------ |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
660 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
661 class TestOnlySetsGenerator(TestOnlySetsInBinaryOps): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
662 def setUp(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
663 def gen(): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
664 for i in xrange(0, 10, 2): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
665 yield i |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
666 self.set = Set((1, 2, 3)) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
667 self.other = gen() |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
668 self.otherIsIterable = True |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
669 |
|
30247
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
670 #------------------------------------------------------------------------------ |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
671 |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
672 class TestOnlySetsofSets(TestOnlySetsInBinaryOps): |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
673 def setUp(self): |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
674 self.set = Set((1, 2, 3)) |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
675 self.other = [Set('ab'), ImmutableSet('cd')] |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
676 self.otherIsIterable = True |
|
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
677 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
678 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
679 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
680 class TestCopying(unittest.TestCase): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
681 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 def test_copy(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 dup = self.set.copy() |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
684 self.assertEqual(len(dup), len(self.set)) |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
685 dup_list = sorted(dup) |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
686 set_list = sorted(self.set) |
|
25029
aff067ba8d07
Rewrote all remaining assert stmts.
Tim Peters <tim.peters@gmail.com>
parents:
25028
diff
changeset
|
687 self.assertEqual(len(dup_list), len(set_list)) |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
688 for i, el in enumerate(dup_list): |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58460
diff
changeset
|
689 self.assertIs(el, set_list[i]) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
691 def test_deep_copy(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
692 dup = copy.deepcopy(self.set) |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58460
diff
changeset
|
693 self.assertSetEqual(dup, self.set) |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
694 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 class TestCopyingEmpty(TestCopying): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
699 self.set = Set() |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
700 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
701 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
702 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 class TestCopyingSingleton(TestCopying): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 self.set = Set(["hello"]) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 class TestCopyingTriple(TestCopying): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
710 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
711 self.set = Set(["zero", 0, None]) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
712 |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
713 def test_copy(self): |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58460
diff
changeset
|
714 with test_support.check_py3k_warnings(): |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
715 super(TestCopyingTriple, self).test_copy() |
|
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
40614
diff
changeset
|
716 |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
717 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
718 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
719 class TestCopyingTuple(TestCopying): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
720 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
721 self.set = Set([(1, 2)]) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
722 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
723 #------------------------------------------------------------------------------ |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 class TestCopyingNested(TestCopying): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 def setUp(self): |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 self.set = Set([((1, 2), (3, 4))]) |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
728 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
729 #============================================================================== |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
731 class TestIdentities(unittest.TestCase): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
732 def setUp(self): |
|
30478
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
733 self.a = Set([random.randrange(100) for i in xrange(50)]) |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
734 self.b = Set([random.randrange(100) for i in xrange(50)]) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
735 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
736 def test_binopsVsSubsets(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
737 a, b = self.a, self.b |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
738 self.assertTrue(a - b <= a) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
739 self.assertTrue(b - a <= b) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
740 self.assertTrue(a & b <= a) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
741 self.assertTrue(a & b <= b) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
742 self.assertTrue(a | b >= a) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
743 self.assertTrue(a | b >= b) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
744 self.assertTrue(a ^ b <= a | b) |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
745 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
746 def test_commutativity(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
747 a, b = self.a, self.b |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
748 self.assertEqual(a&b, b&a) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
749 self.assertEqual(a|b, b|a) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
750 self.assertEqual(a^b, b^a) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
751 if a != b: |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
752 self.assertNotEqual(a-b, b-a) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
753 |
|
30533
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
754 def test_reflexsive_relations(self): |
|
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
755 a, zero = self.a, Set() |
|
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
756 self.assertEqual(a ^ a, zero) |
|
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
757 self.assertEqual(a - a, zero) |
|
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
758 self.assertEqual(a | a, a) |
|
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
759 self.assertEqual(a & a, a) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
760 self.assertTrue(a <= a) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
761 self.assertTrue(a >= a) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
40614
diff
changeset
|
762 self.assertTrue(a == a) |
|
30533
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
763 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
764 def test_summations(self): |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
765 # check that sums of parts equal the whole |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
766 a, b = self.a, self.b |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
767 self.assertEqual((a-b)|(a&b)|(b-a), a|b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
768 self.assertEqual((a&b)|(a^b), a|b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
769 self.assertEqual(a|(b-a), a|b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
770 self.assertEqual((a-b)|b, a|b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
771 self.assertEqual((a-b)|(a&b), a) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
772 self.assertEqual((b-a)|(a&b), b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
773 self.assertEqual((a-b)|(b-a), a^b) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
774 |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
775 def test_exclusion(self): |
|
30478
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
776 # check that inverse operations do not overlap |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
777 a, b, zero = self.a, self.b, Set() |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
778 self.assertEqual((a-b)&b, zero) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
779 self.assertEqual((b-a)&a, zero) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
780 self.assertEqual((a&b)&(a^b), zero) |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
781 |
|
30478
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
782 def test_cardinality_relations(self): |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
783 a, b = self.a, self.b |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
784 self.assertEqual(len(a), len(a-b) + len(a&b)) |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
785 self.assertEqual(len(b), len(b-a) + len(a&b)) |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
786 self.assertEqual(len(a^b), len(a-b) + len(b-a)) |
|
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
787 self.assertEqual(len(a|b), len(a-b) + len(a&b) + len(b-a)) |
|
30533
a15b1c3c236a
Add more identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30478
diff
changeset
|
788 self.assertEqual(len(a^b) + len(a&b), len(a|b)) |
|
30478
b2919a4c558c
Improve and expand identity tests.
Raymond Hettinger <python@rcn.com>
parents:
30247
diff
changeset
|
789 |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
790 #============================================================================== |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
791 |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
792 libreftest = """ |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
793 Example from the Library Reference: Doc/lib/libsets.tex |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
794 |
|
28126
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
795 >>> from sets import Set as Base # override _repr to get sorted output |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
796 >>> class Set(Base): |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
797 ... def _repr(self): |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
798 ... return Base._repr(self, sorted=True) |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
799 >>> engineers = Set(['John', 'Jane', 'Jack', 'Janice']) |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
800 >>> programmers = Set(['Jack', 'Sam', 'Susan', 'Janice']) |
|
30173
9414886f5c7a
Keep doctests in sync with the docs.
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
801 >>> managers = Set(['Jane', 'Jack', 'Susan', 'Zack']) |
|
9414886f5c7a
Keep doctests in sync with the docs.
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
802 >>> employees = engineers | programmers | managers # union |
|
9414886f5c7a
Keep doctests in sync with the docs.
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
803 >>> engineering_management = engineers & managers # intersection |
|
9414886f5c7a
Keep doctests in sync with the docs.
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
804 >>> fulltime_management = managers - engineers - programmers # difference |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
805 >>> engineers.add('Marvin') |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
806 >>> print engineers |
|
28126
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
807 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin']) |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
808 >>> employees.issuperset(engineers) # superset test |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
809 False |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
810 >>> employees.union_update(engineers) # update from another set |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
811 >>> employees.issuperset(engineers) |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
812 True |
|
30173
9414886f5c7a
Keep doctests in sync with the docs.
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
813 >>> for group in [engineers, programmers, managers, employees]: |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
814 ... group.discard('Susan') # unconditionally remove element |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
815 ... print group |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
816 ... |
|
28126
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
817 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin']) |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
818 Set(['Jack', 'Janice', 'Sam']) |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
819 Set(['Jack', 'Jane', 'Zack']) |
|
4cccef9b4d54
The doctest was printing Sets, but that's unreliable because set
Tim Peters <tim.peters@gmail.com>
parents:
27254
diff
changeset
|
820 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin', 'Sam', 'Zack']) |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
821 """ |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
822 |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
823 #============================================================================== |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
824 |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
825 __test__ = {'libreftest' : libreftest} |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
826 |
|
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
827 def test_main(verbose=None): |
| 37408 | 828 import doctest |
| 829 from test import test_sets | |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
830 test_support.run_unittest( |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
831 TestSetOfSets, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
832 TestExceptionPropagation, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
833 TestBasicOpsEmpty, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
834 TestBasicOpsSingleton, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
835 TestBasicOpsTuple, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
836 TestBasicOpsTriple, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
837 TestBinaryOps, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
838 TestUpdateOps, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
839 TestMutate, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
840 TestSubsetEqualEmpty, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
841 TestSubsetEqualNonEmpty, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
842 TestSubsetEmptyNonEmpty, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
843 TestSubsetPartial, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
844 TestSubsetNonOverlap, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
845 TestOnlySetsNumeric, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
846 TestOnlySetsDict, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
847 TestOnlySetsOperator, |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
848 TestOnlySetsTuple, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
849 TestOnlySetsString, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
850 TestOnlySetsGenerator, |
|
30247
95695cc45cdd
SF patch #736962: Port tests to unittest
Raymond Hettinger <python@rcn.com>
parents:
30176
diff
changeset
|
851 TestOnlySetsofSets, |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
852 TestCopyingEmpty, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
853 TestCopyingSingleton, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
854 TestCopyingTriple, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
855 TestCopyingTuple, |
|
30176
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
856 TestCopyingNested, |
|
3db50d31340d
Improvements to set.py:
Raymond Hettinger <python@rcn.com>
parents:
30173
diff
changeset
|
857 TestIdentities, |
|
32984
4b3f8dd9269a
Exercise DocTestSuite's search for __test__.
Raymond Hettinger <python@rcn.com>
parents:
31515
diff
changeset
|
858 doctest.DocTestSuite(test_sets), |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28129
diff
changeset
|
859 ) |
|
24891
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
860 |
|
aebf8c52a842
Set classes and their unit tests, from sandbox.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
861 if __name__ == "__main__": |
|
27254
261547703443
* Add test for __cmp__()
Raymond Hettinger <python@rcn.com>
parents:
26408
diff
changeset
|
862 test_main(verbose=True) |
