1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
from li_std_set import *
s = set_string()
s.append("a")
s.append("b")
s.append("c")
sum = ""
for i in s:
sum = sum + i
if sum != "abc":
raise RuntimeError
i = s.__iter__()
if next(i) != "a":
raise RuntimeError
if next(i) != "b":
raise RuntimeError
if next(i) != "c":
raise RuntimeError
try:
next(i)
raise RuntimeError
except StopIteration as e:
pass
b = s.begin()
e = s.end()
sum = ""
while (b != e):
sum = sum + next(b)
if sum != "abc":
raise RuntimeError
b = s.rbegin()
e = s.rend()
sum = ""
while (b != e):
sum = sum + next(b)
if sum != "cba":
raise RuntimeError
si = set_int()
si.append(1)
si.append(2)
si.append(3)
i = si.__iter__()
if next(i) != 1:
raise RuntimeError
if next(i) != 2:
raise RuntimeError
if next(i) != 3:
raise RuntimeError
if si[0] != 1:
raise RuntimeError
i = s.begin()
next(i)
s.erase(i)
b = s.begin()
e = s.end()
sum = ""
while (b != e):
sum = sum + next(b)
if sum != "ac":
raise RuntimeError
b = s.begin()
e = s.end()
if e - b != 2:
raise RuntimeError
m = b + 1
if m.value() != "c":
raise RuntimeError
s = pyset()
s.insert((1, 2))
s.insert(1)
s.insert("hello")
sum = ()
for i in s:
sum = sum + (i,)
if (len(sum) != 3 or (not 1 in sum) or (not "hello" in sum) or (not (1, 2) in sum)):
raise RuntimeError
# Create from Python set
s = set_string({"x", "y", "z"})
sum = ""
for i in s:
sum = sum + i
if sum != "xyz":
raise RuntimeError
# Compare open and closed iterators
b = s.iterator() # closed iterator
b += 3
try:
b.value()
raise RuntimeError
except StopIteration as e:
pass
b = s.iterator() # closed iterator
try:
b += 4
raise RuntimeError
except StopIteration as e:
pass
b = s.begin() # open iterator
b += 3
# b.value() # undefined behaviour
b = s.begin() # open iterator
# b += 4 # no StopIteration, but can't test this as the iterator is now two off the end, which is undefined behaviour
|