Lines Matching full:set
5 from sets import Set, ImmutableSet
7 empty_set = Set()
15 self.assertEqual(repr(self.set), self.repr)
18 self.assertEqual(len(self.set), self.length)
21 self.assertEqual(self.set, self.set)
24 self.assertEqual(self.set, self.dup)
27 self.assertEqual(self.set.copy(), self.dup)
30 result = self.set | self.set
34 result = self.set | empty_set
38 result = empty_set | self.set
42 result = self.set & self.set
46 result = self.set & empty_set
50 result = empty_set & self.set
54 result = self.set ^ self.set
58 result = self.set ^ empty_set
59 self.assertEqual(result, self.set)
62 result = self.set - self.set
66 result = self.set - empty_set
70 result = empty_set - self.set
74 for v in self.set:
79 p = pickle.dumps(self.set, proto)
81 self.assertEqual(self.set, copy,
82 "%s != %s" % (self.set, copy))
88 self.case = "empty set"
90 self.set = Set(self.values)
91 self.dup = Set(self.values)
93 self.repr = "Set([])"
99 self.case = "unit set (number)"
101 self.set = Set(self.values)
102 self.dup = Set(self.values)
104 self.repr = "Set([3])"
107 self.assertTrue(3 in self.set)
110 self.assertTrue(2 not in self.set)
116 self.case = "unit set (tuple)"
118 self.set = Set(self.values)
119 self.dup = Set(self.values)
121 self.repr = "Set([(0, 'zero')])"
124 self.assertTrue((0, "zero") in self.set)
127 self.assertTrue(9 not in self.set)
133 self.case = "triple set"
135 self.set = Set(self.values)
136 self.dup = Set(self.values)
150 """SF 628246: Set constructor should not trap iterator TypeErrors"""
153 self.assertRaises(TypeError, Set, baditer())
157 Set([1,2,3])
158 Set((1,2,3))
159 Set({'one':1, 'two':2, 'three':3})
160 Set(xrange(3))
161 Set('abc')
162 Set(gooditer())
168 inner = Set([1])
169 outer = Set([inner])
172 outer.add(inner) # Rebuild set of sets with .add method
174 self.assertEqual(outer, Set()) # Verify that remove worked
181 self.set = Set((2, 4, 6))
184 self.assertEqual(self.set, Set({2:1,4:3,6:5}))
187 result = self.set | Set([2])
188 self.assertEqual(result, Set((2, 4, 6)))
191 result = self.set | Set([2, 4, 6, 8])
192 self.assertEqual(result, Set([2, 4, 6, 8]))
195 result = self.set | Set([3, 4, 5])
196 self.assertEqual(result, Set([2, 3, 4, 5, 6]))
199 result = self.set | Set([8])
200 self.assertEqual(result, Set([2, 4, 6, 8]))
203 result = self.set & Set((2, 4))
204 self.assertEqual(result, Set((2, 4)))
207 result = self.set & Set([2, 4, 6, 8])
208 self.assertEqual(result, Set([2, 4, 6]))
211 result = self.set & Set([3, 4, 5])
212 self.assertEqual(result, Set([4]))
215 result = self.set & Set([8])
219 result = self.set ^ Set((2, 4))
220 self.assertEqual(result, Set([6]))
223 result = self.set ^ Set((2, 4, 6, 8))
224 self.assertEqual(result, Set([8]))
227 result = self.set ^ Set((3, 4, 5))
228 self.assertEqual(result, Set([2, 3, 5, 6]))
231 result = self.set ^ Set([8])
232 self.assertEqual(result, Set([2, 4, 6, 8]))
235 a, b = Set('a'), Set('b')
248 t = self.set.copy()
250 self.assertEqual(t, self.set)
252 self.assertEqual(t, self.set)
255 t = self.set.copy()
264 self.set = Set((2, 4, 6))
267 self.set |= Set([2])
268 self.assertEqual(self.set, Set((2, 4, 6)))
271 self.set |= Set([2, 4, 6, 8])
272 self.assertEqual(self.set, Set([2, 4, 6, 8]))
275 self.set |= Set([3, 4, 5])
276 self.assertEqual(self.set, Set([2, 3, 4, 5, 6]))
279 self.set |= Set([8])
280 self.assertEqual(self.set, Set([2, 4, 6, 8]))
283 self.set.union_update(Set([3, 4, 5]))
284 self.assertEqual(self.set, Set([2, 3, 4, 5, 6]))
287 self.set &= Set((2, 4))
288 self.assertEqual(self.set, Set((2, 4)))
291 self.set &= Set([2, 4, 6, 8])
292 self.assertEqual(self.set, Set([2, 4, 6]))
295 self.set &= Set([3, 4, 5])
296 self.assertEqual(self.set, Set([4]))
299 self.set &= Set([8])
300 self.assertEqual(self.set, empty_set)
303 self.set.intersection_update(Set([3, 4, 5]))
304 self.assertEqual(self.set, Set([4]))
307 self.set ^= Set((2, 4))
308 self.assertEqual(self.set, Set([6]))
311 self.set ^= Set((2, 4, 6, 8))
312 self.assertEqual(self.set, Set([8]))
315 self.set ^= Set((3, 4, 5))
316 self.assertEqual(self.set, Set([2, 3, 5, 6]))
319 self.set ^= Set([8])
320 self.assertEqual(self.set, Set([2, 4, 6, 8]))
323 self.set.symmetric_difference_update(Set([3, 4, 5]))
324 self.assertEqual(self.set, Set([2, 3, 5, 6]))
327 self.set -= Set((2, 4))
328 self.assertEqual(self.set, Set([6]))
331 self.set -= Set((2, 4, 6, 8))
332 self.assertEqual(self.set, Set([]))
335 self.set -= Set((3, 4, 5))
336 self.assertEqual(self.set, Set([2, 6]))
339 self.set -= Set([8])
340 self.assertEqual(self.set, Set([2, 4, 6]))
343 self.set.difference_update(Set([3, 4, 5]))
344 self.assertEqual(self.set, Set([2, 6]))
351 self.set = Set(self.values)
354 self.set.add("c")
355 self.assertEqual(self.set, Set("abc"))
358 self.set.add("d")
359 self.assertEqual(self.set, Set("abcd"))
362 tmp = Set()
368 self.assertEqual(tmp, self.set)
371 self.set.remove("b")
372 self.assertEqual(self.set, Set("ac"))
376 self.set.remove("d")
382 expected_len = len(self.set)
384 self.set.remove(v)
386 self.assertEqual(len(self.set), expected_len)
389 self.set.discard("c")
390 self.assertEqual(self.set, Set("ab"))
393 self.set.discard("d")
394 self.assertEqual(self.set, Set("abc"))
397 self.set.clear()
398 self.assertEqual(len(self.set), 0)
402 while self.set:
403 popped[self.set.pop()] = None
409 self.set.union_update(())
410 self.assertEqual(self.set, Set(self.values))
413 self.set.union_update(("a",))
414 self.assertEqual(self.set, Set(self.values))
417 self.set.union_update(("a", "z"))
418 self.assertEqual(self.set, Set(self.values + ["z"]))
461 left = Set()
462 right = Set()
469 left = Set([1, 2])
470 right = Set([1, 2])
477 left = Set()
478 right = Set([1, 2])
485 left = Set([1])
486 right = Set([1, 2])
493 left = Set([1])
494 right = Set([2])
504 self.assertEqual(self.other == self.set, False)
505 self.assertEqual(self.set == self.other, False)
506 self.assertEqual(self.other != self.set, True)
507 self.assertEqual(self.set != self.other, True)
510 self.assertRaises(TypeError, lambda: self.set < self.other)
511 self.assertRaises(TypeError, lambda: self.set <= self.other)
512 self.assertRaises(TypeError, lambda: self.set > self.other)
513 self.assertRaises(TypeError, lambda: self.set >= self.other)
515 self.assertRaises(TypeError, lambda: self.other < self.set)
516 self.assertRaises(TypeError, lambda: self.other <= self.set)
517 self.assertRaises(TypeError, lambda: self.other > self.set)
518 self.assertRaises(TypeError, lambda: self.other >= self.set)
522 self.set |= self.other
530 self.set.union_update(self.other)
532 self.assertRaises(TypeError, self.set.union_update, self.other)
535 self.assertRaises(TypeError, lambda: self.set | self.other)
536 self.assertRaises(TypeError, lambda: self.other | self.set)
538 self.set.union(self.other)
540 self.assertRaises(TypeError, self.set.union, self.other)
544 self.set &= self.other
552 self.set.intersection_update(self.other)
555 self.set.intersection_update,
559 self.assertRaises(TypeError, lambda: self.set & self.other)
560 self.assertRaises(TypeError, lambda: self.other & self.set)
562 self.set.intersection(self.other)
564 self.assertRaises(TypeError, self.set.intersection, self.other)
568 self.set ^= self.other
576 self.set.symmetric_difference_update(self.other)
579 self.set.symmetric_difference_update,
583 self.assertRaises(TypeError, lambda: self.set ^ self.other)
584 self.assertRaises(TypeError, lambda: self.other ^ self.set)
586 self.set.symmetric_difference(self.other)
588 self.assertRaises(TypeError, self.set.symmetric_difference, self.other)
592 self.set -= self.other
600 self.set.difference_update(self.other)
603 self.set.difference_update,
607 self.assertRaises(TypeError, lambda: self.set - self.other)
608 self.assertRaises(TypeError, lambda: self.other - self.set)
610 self.set.difference(self.other)
612 self.assertRaises(TypeError, self.set.difference, self.other)
618 self.set = Set((1, 2, 3))
626 self.set = Set((1, 2, 3))
634 self.set = Set((1, 2, 3))
646 self.set = Set((1, 2, 3))
654 self.set = Set((1, 2, 3))
665 self.set = Set((1, 2, 3))
673 self.set = Set((1, 2, 3))
674 self.other = [Set('ab'), ImmutableSet('cd')]
682 dup = self.set.copy()
683 self.assertEqual(len(dup), len(self.set))
685 set_list = sorted(self.set)
691 dup = copy.deepcopy(self.set)
692 self.assertSetEqual(dup, self.set)
698 self.set = Set()
704 self.set = Set(["hello"])
710 self.set = Set(["zero", 0, None])
720 self.set = Set([(1, 2)])
726 self.set = Set([((1, 2), (3, 4))])
732 self.a = Set([random.randrange(100) for i in xrange(50)])
733 self.b = Set([random.randrange(100) for i in xrange(50)])
754 a, zero = self.a, Set()
776 a, b, zero = self.a, self.b, Set()
794 >>> from sets import Set as Base # override _repr to get sorted output
795 >>> class Set(Base):
798 >>> engineers = Set(['John', 'Jane', 'Jack', 'Janice'])
799 >>> programmers = Set(['Jack', 'Sam', 'Susan', 'Janice'])
800 >>> managers = Set(['Jane', 'Jack', 'Susan', 'Zack'])
806 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin'])
809 >>> employees.union_update(engineers) # update from another set
816 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin'])
817 Set(['Jack', 'Janice', 'Sam'])
818 Set(['Jack', 'Jane', 'Zack'])
819 Set(['Jack', 'Jane', 'Janice', 'John', 'Marvin', 'Sam', 'Zack'])