Commit 1422865c authored by Damien George's avatar Damien George
Browse files

Merge pull request #445 from lurch/test-sorted-sets

Modify set tests to print sorted sets directly
parents a28507ab 1ff6011a
s = {1, 2, 3, 4}
print(s.add(5))
l = list(s)
l.sort()
print(l)
print(sorted(s))
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)
......@@ -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))
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))
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))
......@@ -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))
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))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment