|
18 | 18 | assert _ints_slice[0] == 2 |
19 | 19 | assert _ints_slice[1] == 3 |
20 | 20 |
|
| 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 | + |
21 | 110 | # print(ints.tolist()) |
22 | 111 |
|
23 | 112 | vecs = std_array.get_arr_3_vecs() |
|
0 commit comments