idmap_tdb_common: fix a debug message in idmap_tdb_common_unixid_to_sid()
[Samba/wip.git] / lib / dnspython / tests / set.py
blob583d20cfa053ad7b40435162ba0abd6f57e073fc
1 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
3 # Permission to use, copy, modify, and distribute this software and its
4 # documentation for any purpose with or without fee is hereby granted,
5 # provided that the above copyright notice and this permission notice
6 # appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 import unittest
18 import dns.set
20 # for convenience
21 S = dns.set.Set
23 class SimpleSetTestCase(unittest.TestCase):
25 def testLen1(self):
26 s1 = S()
27 self.failUnless(len(s1) == 0)
29 def testLen2(self):
30 s1 = S([1, 2, 3])
31 self.failUnless(len(s1) == 3)
33 def testLen3(self):
34 s1 = S([1, 2, 3, 3, 3])
35 self.failUnless(len(s1) == 3)
37 def testUnion1(self):
38 s1 = S([1, 2, 3])
39 s2 = S([1, 2, 3])
40 e = S([1, 2, 3])
41 self.failUnless(s1 | s2 == e)
43 def testUnion2(self):
44 s1 = S([1, 2, 3])
45 s2 = S([])
46 e = S([1, 2, 3])
47 self.failUnless(s1 | s2 == e)
49 def testUnion3(self):
50 s1 = S([1, 2, 3])
51 s2 = S([3, 4])
52 e = S([1, 2, 3, 4])
53 self.failUnless(s1 | s2 == e)
55 def testIntersection1(self):
56 s1 = S([1, 2, 3])
57 s2 = S([1, 2, 3])
58 e = S([1, 2, 3])
59 self.failUnless(s1 & s2 == e)
61 def testIntersection2(self):
62 s1 = S([0, 1, 2, 3])
63 s2 = S([1, 2, 3, 4])
64 e = S([1, 2, 3])
65 self.failUnless(s1 & s2 == e)
67 def testIntersection3(self):
68 s1 = S([1, 2, 3])
69 s2 = S([])
70 e = S([])
71 self.failUnless(s1 & s2 == e)
73 def testIntersection4(self):
74 s1 = S([1, 2, 3])
75 s2 = S([5, 4])
76 e = S([])
77 self.failUnless(s1 & s2 == e)
79 def testDifference1(self):
80 s1 = S([1, 2, 3])
81 s2 = S([5, 4])
82 e = S([1, 2, 3])
83 self.failUnless(s1 - s2 == e)
85 def testDifference2(self):
86 s1 = S([1, 2, 3])
87 s2 = S([])
88 e = S([1, 2, 3])
89 self.failUnless(s1 - s2 == e)
91 def testDifference3(self):
92 s1 = S([1, 2, 3])
93 s2 = S([3, 2])
94 e = S([1])
95 self.failUnless(s1 - s2 == e)
97 def testDifference4(self):
98 s1 = S([1, 2, 3])
99 s2 = S([3, 2, 1])
100 e = S([])
101 self.failUnless(s1 - s2 == e)
103 def testSubset1(self):
104 s1 = S([1, 2, 3])
105 s2 = S([3, 2, 1])
106 self.failUnless(s1.issubset(s2))
108 def testSubset2(self):
109 s1 = S([1, 2, 3])
110 self.failUnless(s1.issubset(s1))
112 def testSubset3(self):
113 s1 = S([])
114 s2 = S([1, 2, 3])
115 self.failUnless(s1.issubset(s2))
117 def testSubset4(self):
118 s1 = S([1])
119 s2 = S([1, 2, 3])
120 self.failUnless(s1.issubset(s2))
122 def testSubset5(self):
123 s1 = S([])
124 s2 = S([])
125 self.failUnless(s1.issubset(s2))
127 def testSubset6(self):
128 s1 = S([1, 4])
129 s2 = S([1, 2, 3])
130 self.failUnless(not s1.issubset(s2))
132 def testSuperset1(self):
133 s1 = S([1, 2, 3])
134 s2 = S([3, 2, 1])
135 self.failUnless(s1.issuperset(s2))
137 def testSuperset2(self):
138 s1 = S([1, 2, 3])
139 self.failUnless(s1.issuperset(s1))
141 def testSuperset3(self):
142 s1 = S([1, 2, 3])
143 s2 = S([])
144 self.failUnless(s1.issuperset(s2))
146 def testSuperset4(self):
147 s1 = S([1, 2, 3])
148 s2 = S([1])
149 self.failUnless(s1.issuperset(s2))
151 def testSuperset5(self):
152 s1 = S([])
153 s2 = S([])
154 self.failUnless(s1.issuperset(s2))
156 def testSuperset6(self):
157 s1 = S([1, 2, 3])
158 s2 = S([1, 4])
159 self.failUnless(not s1.issuperset(s2))
161 def testUpdate1(self):
162 s1 = S([1, 2, 3])
163 u = (4, 5, 6)
164 e = S([1, 2, 3, 4, 5, 6])
165 s1.update(u)
166 self.failUnless(s1 == e)
168 def testUpdate2(self):
169 s1 = S([1, 2, 3])
170 u = []
171 e = S([1, 2, 3])
172 s1.update(u)
173 self.failUnless(s1 == e)
175 def testGetitem(self):
176 s1 = S([1, 2, 3])
177 i0 = s1[0]
178 i1 = s1[1]
179 i2 = s1[2]
180 s2 = S([i0, i1, i2])
181 self.failUnless(s1 == s2)
183 def testGetslice(self):
184 s1 = S([1, 2, 3])
185 slice = s1[0:2]
186 self.failUnless(len(slice) == 2)
187 item = s1[2]
188 slice.append(item)
189 s2 = S(slice)
190 self.failUnless(s1 == s2)
192 def testDelitem(self):
193 s1 = S([1, 2, 3])
194 del s1[0]
195 i1 = s1[0]
196 i2 = s1[1]
197 self.failUnless(i1 != i2)
198 self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)
199 self.failUnless(i2 == 1 or i2 == 2 or i2 == 3)
201 def testDelslice(self):
202 s1 = S([1, 2, 3])
203 del s1[0:2]
204 i1 = s1[0]
205 self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)
207 if __name__ == '__main__':
208 unittest.main()