Browse Source

Modify set tests to print sorted sets directly

instead of creating temporary lists and sorting those in-place
pull/445/head
Andrew Scheller 11 years ago
parent
commit
1ff6011abc
  1. 4
      tests/basics/set_add.py
  2. 32
      tests/basics/set_binop.py
  3. 4
      tests/basics/set_copy.py
  4. 13
      tests/basics/set_difference.py
  5. 13
      tests/basics/set_intersection.py
  6. 4
      tests/basics/set_symmetric_difference.py
  7. 11
      tests/basics/set_update.py

4
tests/basics/set_add.py

@ -1,5 +1,3 @@
s = {1, 2, 3, 4}
print(s.add(5))
l = list(s)
l.sort()
print(l)
print(sorted(s))

32
tests/basics/set_binop.py

@ -1,30 +1,26 @@
def r(s):
l = list(s)
l.sort()
return l
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}]
for s in sets:
for t in sets:
print(r(s), '|', r(t), '=', r(s | t))
print(r(s), '^', r(t), '=', r(s ^ t))
print(r(s), '&', r(t), '=', r(s & t))
print(r(s), '-', r(t), '=', r(s - t))
print(sorted(s), '|', sorted(t), '=', sorted(s | t))
print(sorted(s), '^', sorted(t), '=', sorted(s ^ t))
print(sorted(s), '&', sorted(t), '=', sorted(s & t))
print(sorted(s), '-', sorted(t), '=', sorted(s - t))
u = s.copy()
u |= t
print(r(s), "|=", r(t), '-->', r(u))
print(sorted(s), "|=", sorted(t), '-->', sorted(u))
u = s.copy()
u ^= t
print(r(s), "^=", r(t), '-->', r(u))
print(sorted(s), "^=", sorted(t), '-->', sorted(u))
u = s.copy()
u &= t
print(r(s), "&=", r(t), "-->", r(u))
print(sorted(s), "&=", sorted(t), "-->", sorted(u))
u = s.copy()
u -= t
print(r(s), "-=", r(t), "-->", r(u))
print(sorted(s), "-=", sorted(t), "-->", sorted(u))
print(r(s), '==', r(t), '=', s == t)
print(r(s), '!=', r(t), '=', s != t)
print(r(s), '>', r(t), '=', s > t)
print(r(s), '>=', r(t), '=', s >= t)
print(r(s), '<', r(t), '=', s < t)
print(r(s), '<=', r(t), '=', s <= t)
print(sorted(s), '==', sorted(t), '=', s == t)
print(sorted(s), '!=', sorted(t), '=', s != t)
print(sorted(s), '>', sorted(t), '=', s > t)
print(sorted(s), '>=', sorted(t), '=', s >= t)
print(sorted(s), '<', sorted(t), '=', s < t)
print(sorted(s), '<=', sorted(t), '=', s <= t)

4
tests/basics/set_copy.py

@ -3,6 +3,4 @@ t = s.copy()
s.add(5)
t.add(7)
for i in s, t:
l = list(i)
l.sort()
print(l)
print(sorted(i))

13
tests/basics/set_difference.py

@ -1,8 +1,3 @@
def report(s):
l = list(s)
l.sort()
print(l)
l = [1, 2, 3, 4]
s = set(l)
outs = [s.difference(),
@ -10,12 +5,12 @@ outs = [s.difference(),
s.difference({1}, [1, 2]),
s.difference({1}, {1, 2}, {2, 3})]
for out in outs:
report(out)
print(sorted(out))
s = set(l)
print(s.difference_update())
report(s)
print(sorted(s))
print(s.difference_update({1}))
report(s)
print(sorted(s))
print(s.difference_update({1}, [2]))
report(s)
print(sorted(s))

13
tests/basics/set_intersection.py

@ -1,12 +1,7 @@
def report(s):
l = list(s)
l.sort()
print(l)
s = {1, 2, 3, 4}
report(s)
report(s.intersection({1, 3}))
report(s.intersection([3, 4]))
print(sorted(s))
print(sorted(s.intersection({1, 3})))
print(sorted(s.intersection([3, 4])))
print(s.intersection_update([1]))
report(s)
print(sorted(s))

4
tests/basics/set_symmetric_difference.py

@ -2,6 +2,4 @@ print(sorted({1,2}.symmetric_difference({2,3})))
print(sorted({1,2}.symmetric_difference([2,3])))
s = {1,2}
print(s.symmetric_difference_update({2,3}))
l = list(s)
l.sort()
print(l)
print(sorted(s))

11
tests/basics/set_update.py

@ -1,12 +1,7 @@
def report(s):
l = list(s)
l.sort()
print(l)
s = {1}
s.update()
report(s)
print(s)
s.update([2])
report(s)
print(sorted(s))
s.update([1,3], [2,2,4])
report(s)
print(sorted(s))

Loading…
Cancel
Save