objset: Add frozenset tests, skippable if frozenset not available.
This commit is contained in:
parent
43d4a6fa31
commit
37b0f33545
|
@ -0,0 +1,14 @@
|
|||
# basic sets
|
||||
|
||||
try:
|
||||
frozenset
|
||||
except NameError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
s = frozenset({1})
|
||||
print(s)
|
||||
|
||||
s = frozenset({3, 4, 3, 1})
|
||||
print(sorted(s))
|
|
@ -0,0 +1,12 @@
|
|||
try:
|
||||
frozenset
|
||||
except NameError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
s = frozenset({1, 2, 3, 4})
|
||||
try:
|
||||
print(s.add(5))
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
|
@ -0,0 +1,36 @@
|
|||
try:
|
||||
frozenset
|
||||
except NameError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
sets = [
|
||||
frozenset(), frozenset({1}), frozenset({1, 2}), frozenset({1, 2, 3}), frozenset({2, 3}),
|
||||
frozenset({2, 3, 5}), frozenset({5}), frozenset({7})
|
||||
]
|
||||
for s in sets:
|
||||
for t in sets:
|
||||
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(sorted(s), "|=", sorted(t), '-->', sorted(u))
|
||||
u = s.copy()
|
||||
u ^= t
|
||||
print(sorted(s), "^=", sorted(t), '-->', sorted(u))
|
||||
u = s.copy()
|
||||
u &= t
|
||||
print(sorted(s), "&=", sorted(t), "-->", sorted(u))
|
||||
u = s.copy()
|
||||
u -= t
|
||||
print(sorted(s), "-=", sorted(t), "-->", sorted(u))
|
||||
|
||||
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)
|
|
@ -0,0 +1,12 @@
|
|||
try:
|
||||
frozenset
|
||||
except NameError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
s = frozenset({1, 2, 3, 4})
|
||||
t = s.copy()
|
||||
print(type(t))
|
||||
for i in s, t:
|
||||
print(sorted(i))
|
|
@ -0,0 +1,21 @@
|
|||
try:
|
||||
frozenset
|
||||
except NameError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
l = [1, 2, 3, 4]
|
||||
s = frozenset(l)
|
||||
outs = [s.difference(),
|
||||
s.difference(frozenset({1})),
|
||||
s.difference(frozenset({1}), [1, 2]),
|
||||
s.difference(frozenset({1}), {1, 2}, {2, 3})]
|
||||
for out in outs:
|
||||
print(type(out), sorted(out))
|
||||
|
||||
s = frozenset(l)
|
||||
try:
|
||||
print(s.difference_update({1}))
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
Loading…
Reference in New Issue