t435.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. s = set(range(9))
  2. s1 = set(range(5))
  3. s2 = set(range(4,9))
  4. print "\nlen"
  5. print len(set([])) == 0
  6. print len(s1) == len(s2) == 5
  7. print "\nx in s"
  8. print (4 in s1) == (4 in s2) == True
  9. print (8 in s1) == (1 in s2) == False
  10. print "\nx not in s"
  11. print (1 not in s1) == (8 not in s2) == False
  12. print (8 not in s1) == (1 not in s2) == True
  13. print "\nisdisjoint(other)"
  14. print s1.isdisjoint(s2) == False
  15. print s1.isdisjoint(set(range(5,10))) == True
  16. print "\nissubset(other)"
  17. print s1.issubset(s1) == True
  18. print s1.issubset(s) == True
  19. print s1.issubset(s2) == False
  20. print "\nset <= other"
  21. print (s1 <= s) == True
  22. print (s2 <= s) == True
  23. print (s <= s) == True
  24. print (s1 <= s2) == False
  25. print "\nset < other"
  26. print (s1 < s) == True
  27. print (s2 < s) == True
  28. print (s < s) == False
  29. print (s1 < s2) == False
  30. print "\nissuperset(other)"
  31. print s2.issuperset(s2) == True
  32. print s.issuperset(s1) == True
  33. print s2.issuperset(s1) == False
  34. print "\nset >= other"
  35. print (s >= s1) == True
  36. print (s >= s2) == True
  37. print (s >= s) == True
  38. print (s1 >= s2) == False
  39. print "\nset > other"
  40. print (s > s1) == True
  41. print (s > s2) == True
  42. print (s > s) == False
  43. print (s1 > s2) == False
  44. print "\nunion(other,...)"
  45. print set([]).union(s1) == s1
  46. print s1.union(set([])) == s1
  47. print s1.union(s2) == s
  48. print s1.union(s2,set([4,5,6])) == s
  49. print "\nintersection(other,...)"
  50. print set([]).intersection(s1) == set([])
  51. print s1.intersection(set([])) == set([])
  52. print s1.intersection(s2) == set([4])
  53. print s.intersection(s1,s2) == set([4])
  54. print "\ndifference(other,...)"
  55. print set([]).difference(s1) == set([])
  56. print s1.difference(set([])) == s1
  57. print s1.difference(s2) == set([0,1,2,3])
  58. print s.difference(s1,s2) == set([])
  59. print "\nsymmetric_difference(other)"
  60. print set([]).symmetric_difference(s1) == s1
  61. print s1.symmetric_difference(set([])) == s1
  62. print s1.symmetric_difference(s2) == set([0,1,2,3,5,6,7,8])
  63. print s.symmetric_difference(s1.symmetric_difference(s2)) == set([4])
  64. print "\ncopy()"
  65. print set([]).copy() == set([])
  66. print s1.copy() == s1
  67. s3 = s1.copy()
  68. s1 = set(range(1,5))
  69. print s1 != s3
  70. s3 = s1.copy()
  71. s1.add(0)
  72. print s1 != s3
  73. print "\nupdate(other,...)"
  74. empty = set([])
  75. empty.update(s1); print empty == s1
  76. empty.update(set([])); print empty == s1
  77. empty.update(s2); print empty == s
  78. empty.update(s1,s2,set([4,5,6])); print empty == s
  79. print "\nintersection_update(other,...)"
  80. empty = set([])
  81. empty.intersection_update(s1); print empty == set([])
  82. empty = s1.copy()
  83. empty.intersection_update(set([])); print empty == set([])
  84. empty = s1.copy()
  85. empty.intersection_update(s2); print empty == set([4])
  86. empty = s.copy()
  87. empty.intersection_update(s1,s2); print empty == set([4])
  88. print "\ndifference(other,...)"
  89. empty = set([])
  90. empty.difference_update(s1); print empty == set([])
  91. empty = s1.copy()
  92. empty.difference_update(set([])); print empty == s1
  93. empty.difference_update(s2); print empty == set([0,1,2,3])
  94. empty = s.copy()
  95. empty.difference_update(s1,s2); print empty == set([])
  96. print "\nsymmetric_difference_update(other)"
  97. empty = set([])
  98. empty.symmetric_difference_update(s1); print empty == s1
  99. empty.symmetric_difference_update(set([])); print empty == s1
  100. empty.symmetric_difference_update(s2); print empty == set([0,1,2,3,5,6,7,8])
  101. print s.symmetric_difference(empty) == set([4])
  102. print "\nadd(elem)"
  103. empty = set([])
  104. empty.add(1); print empty == set([1])
  105. s1.add(5); print s1 == set([0,1,2,3,4,5])
  106. print "\nremove(elem)"
  107. empty.remove(1); print empty == set([])
  108. s1.remove(5); print s1 == set([0,1,2,3,4])
  109. print "\ndiscard(elem)"
  110. empty.discard(500); print empty == set([])
  111. s1.discard(4); print s1 == set([0,1,2,3])
  112. print "\npop()"
  113. print s1.pop() in set([0,1,2,3])
  114. print s1.pop() in set([0,1,2,3])
  115. print s1.pop() in set([0,1,2,3])
  116. print s1.pop() in set([0,1,2,3])
  117. print len(s1) == 0