Skip to content

Commit cc30e46

Browse files
committed
[std-array] Test array edge cases
1 parent 6ad6448 commit cc30e46

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

unittest/python/test_std_array.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,95 @@
1818
assert _ints_slice[0] == 2
1919
assert _ints_slice[1] == 3
2020

21+
# Test that insert/delete is impossible with the slice operator
22+
23+
# prepend
24+
try:
25+
ints[0:0] = [0, 1]
26+
except NotImplementedError:
27+
pass
28+
else:
29+
assert False, "Insert value with slice operator should be impossible"
30+
31+
# append
32+
try:
33+
ints[10:12] = [0]
34+
except NotImplementedError:
35+
pass
36+
else:
37+
assert False, "Insert value with slice operator should be impossible"
38+
39+
# append
40+
try:
41+
ints[3:3] = [0]
42+
except NotImplementedError:
43+
pass
44+
else:
45+
assert False, "Insert value with slice operator should be impossible"
46+
47+
# Erase two elements and replace by one
48+
try:
49+
ints[1:3] = [0]
50+
except NotImplementedError:
51+
pass
52+
else:
53+
assert False, "Insert value with slice operator should be impossible"
54+
55+
# Erase two elements and replace by three
56+
try:
57+
ints[1:3] = [0, 1, 2]
58+
except NotImplementedError:
59+
pass
60+
else:
61+
assert False, "Insert value with slice operator should be impossible"
62+
63+
# Test that delete operator is not implemented
64+
# Index delete
65+
try:
66+
del ints[0]
67+
except NotImplementedError:
68+
pass
69+
else:
70+
assert False, "del is not implemented"
71+
72+
# Slice delete
73+
try:
74+
del ints[1:3]
75+
except NotImplementedError:
76+
pass
77+
else:
78+
assert False, "del is not implemented"
79+
80+
# Slice delete
81+
try:
82+
del ints[1:3]
83+
except NotImplementedError:
84+
pass
85+
else:
86+
assert False, "del is not implemented"
87+
88+
# Test that append/extend are not implemented
89+
# append
90+
try:
91+
ints.append(4)
92+
except AttributeError:
93+
pass
94+
else:
95+
assert False, "append is not implemented"
96+
97+
# extend
98+
try:
99+
ints.extend([4, 5])
100+
except AttributeError:
101+
pass
102+
else:
103+
assert False, "extend is not implemented"
104+
105+
# Test set_slice nominal case
106+
ints[1:3] = [10, 20]
107+
assert ints[1] == 10
108+
assert ints[2] == 20
109+
21110
# print(ints.tolist())
22111

23112
vecs = std_array.get_arr_3_vecs()

0 commit comments

Comments
 (0)