mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-17 01:51:39 +09:00
78 lines
1.4 KiB
Python
78 lines
1.4 KiB
Python
x = [1, 2, 3]
|
|
assert x[0] == 1
|
|
assert x[1] == 2
|
|
# assert x[7]
|
|
|
|
y = [2, *x]
|
|
assert y == [2, 1, 2, 3]
|
|
|
|
y.extend(x)
|
|
assert y == [2, 1, 2, 3, 1, 2, 3]
|
|
|
|
assert x * 0 == [], "list __mul__ by 0 failed"
|
|
assert x * -1 == [], "list __mul__ by -1 failed"
|
|
assert x * 2 == [1, 2, 3, 1, 2, 3], "list __mul__ by 2 failed"
|
|
|
|
# index()
|
|
assert ['a', 'b', 'c'].index('b') == 1
|
|
assert [5, 6, 7].index(7) == 2
|
|
try:
|
|
['a', 'b', 'c'].index('z')
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
assert False, "ValueError was not raised"
|
|
|
|
x = [[1,0,-3], 'a', 1]
|
|
y = [[3,2,1], 'z', 2]
|
|
assert x < y, "list __lt__ failed"
|
|
|
|
x = [5, 13, 31]
|
|
y = [1, 10, 29]
|
|
assert x > y, "list __gt__ failed"
|
|
|
|
|
|
assert [1,2,'a'].pop() == 'a', "list pop failed"
|
|
try:
|
|
[].pop()
|
|
except IndexError:
|
|
pass
|
|
else:
|
|
assert False, "IndexError was not raised"
|
|
|
|
recursive = []
|
|
recursive.append(recursive)
|
|
assert repr(recursive) == "[[...]]"
|
|
|
|
# insert()
|
|
x = ['a', 'b', 'c']
|
|
x.insert(0, 'z') # insert is in-place, no return value
|
|
assert x == ['z', 'a', 'b', 'c']
|
|
|
|
x = ['a', 'b', 'c']
|
|
x.insert(100, 'z')
|
|
assert x == ['a', 'b', 'c', 'z']
|
|
|
|
x = ['a', 'b', 'c']
|
|
x.insert(-1, 'z')
|
|
assert x == ['a', 'b', 'z', 'c']
|
|
|
|
x = ['a', 'b', 'c']
|
|
x.insert(-100, 'z')
|
|
assert x == ['z', 'a', 'b', 'c']
|
|
|
|
try:
|
|
x.insert(100000000000000000000, 'z')
|
|
except OverflowError:
|
|
pass
|
|
else:
|
|
assert False, "OverflowError was not raised"
|
|
|
|
x = [[], 2, {}]
|
|
y = x.copy()
|
|
assert x is not y
|
|
assert x == y
|
|
assert all(a is b for a, b in zip(x, y))
|
|
y.append(4)
|
|
assert x != y
|