objset: Add frozenset tests, skippable if frozenset not available.

This commit is contained in:
Paul Sokolovsky 2014-05-10 16:54:23 +03:00
parent 43d4a6fa31
commit 37b0f33545
5 changed files with 95 additions and 0 deletions

View File

@ -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))

View File

@ -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")

View File

@ -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)

View File

@ -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))

View File

@ -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")