Lichen

Annotated tests/set.py

582:26f221305c30
2017-02-13 Paul Boddie Set instantiator arguments to null, preventing context test rejection. method-wrapper-for-context
paul@542 1
s = set()
paul@542 2
s.add(10)
paul@542 3
s.add(20)
paul@542 4
s.add("c")
paul@542 5
s.add((1, 2))
paul@544 6
paul@542 7
print "# s:",
paul@544 8
print s                             # set([10, 20, "c", (1, 2))
paul@544 9
print len(s)                        # 4
paul@544 10
print 10 in s                       # True
paul@544 11
print 20 in s                       # True
paul@544 12
print "c" in s                      # True
paul@544 13
print 30 in s                       # False
paul@544 14
print (1, 2) in s                   # True
paul@542 15
paul@542 16
s2 = set([10, 20, "c", (1, 2)])
paul@544 17
paul@542 18
print "# s2:",
paul@544 19
print s2                            # set([10, 20, "c", (1, 2))
paul@544 20
print len(s2)                       # 4
paul@544 21
print 10 in s2                      # True
paul@544 22
print 20 in s2                      # True
paul@544 23
print "c" in s2                     # True
paul@544 24
print 30 in s2                      # False
paul@544 25
print (1, 2) in s2                  # True
paul@544 26
paul@544 27
a = set([1, 3, 5, 7, 9])
paul@544 28
b = set([1, 2, 3, 5, 7])
paul@544 29
paul@544 30
aub = a.union(b)
paul@544 31
aib = a.intersection(b)
paul@544 32
adb = a.difference(b)
paul@544 33
asdb = a.symmetric_difference(b)
paul@544 34
paul@544 35
print len(aub)                      # 6
paul@544 36
print len(aib)                      # 4
paul@544 37
print len(adb)                      # 1
paul@544 38
print len(asdb)                     # 2
paul@544 39
print
paul@544 40
print 1 in aub                      # True
paul@544 41
print 1 in aib                      # True
paul@544 42
print 1 in adb                      # False
paul@544 43
print 1 in asdb                     # True
paul@544 44
print
paul@544 45
print 2 in aub                      # True
paul@544 46
print 2 in aib                      # False
paul@544 47
print 2 in adb                      # False
paul@544 48
print 2 in asdb                     # False
paul@544 49
print
paul@544 50
print 9 in aub                      # True
paul@544 51
print 9 in aib                      # False
paul@544 52
print 9 in adb                      # True
paul@544 53
print 9 in asdb                     # False
paul@549 54
print
paul@549 55
paul@549 56
aub2 = a.copy()
paul@549 57
aub2.update(b)
paul@549 58
print len(aub2)                     # 6
paul@549 59
paul@549 60
aib2 = a.copy()
paul@549 61
aib2.intersection_update(b)
paul@549 62
print len(aib2)                     # 4
paul@549 63
paul@549 64
adb2 = a.copy()
paul@549 65
adb2.difference_update(b)
paul@549 66
print len(adb2)                     # 1
paul@549 67
paul@549 68
asdb2 = a.copy()
paul@549 69
asdb2.symmetric_difference_update(b)
paul@549 70
print len(asdb2)                    # 2