-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_sequence.py
58 lines (35 loc) · 1.23 KB
/
test_sequence.py
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
import pytest
from cstring import cstring
def test_len():
result = cstring('hello, world')
assert len(result) == 12
def test_concat():
result = cstring('hello') + cstring(', ') + cstring('world')
assert 'hello, world' == str(result)
def test_concat_TypeError():
with pytest.raises(TypeError, match='^Object must have type cstring, not str.$'):
cstring('hello') + 'world'
def test_repeat_zero():
result = cstring('hello') * 0
assert result == cstring('')
def test_repeat_five():
result = cstring('hello') * 5
assert result == cstring('hellohellohellohellohello')
def test_item_IndexError_too_small():
with pytest.raises(IndexError):
result = cstring('hello')[-6]
def test_item_ok_neg():
result = cstring('hello')[-5]
assert isinstance(result, cstring)
assert result == cstring('h')
def test_item_IndexError_too_big():
with pytest.raises(IndexError):
result = cstring('hello')[5]
def test_item_ok_pos():
result = cstring('hello')[4]
assert isinstance(result, cstring)
assert result == cstring('o')
def test_contains_True():
assert cstring('ell') in cstring('hello')
def test_contains_False():
assert cstring('hello') not in cstring('world')