-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_linked_list.py
More file actions
69 lines (43 loc) · 1.61 KB
/
test_linked_list.py
File metadata and controls
69 lines (43 loc) · 1.61 KB
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
from __future__ import unicode_literals
import pytest
import linked_list as ll
@pytest.fixture
def base_llist():
return ll.LinkedList([1, 2, 3])
def test_construct_from_iterable_valid(base_llist):
expected_output = "(1, 2, 3)"
assert base_llist.display() == expected_output
def test_construct_from_nested_iterable_valid():
arg = ([1, 2, 3], 'string')
expected_output = "([1, 2, 3], u'string')"
assert ll.LinkedList(arg).__repr__() == expected_output
def test_construct_from_string_valid():
arg = "string"
expected_output = "(u's', u't', u'r', u'i', u'n', u'g')"
assert ll.LinkedList(arg).__repr__() == expected_output
def test_construct_empty_valid():
expected_output = "()"
assert ll.LinkedList().__repr__() == expected_output
def test_construct_from_none_fails():
with pytest.raises(TypeError):
ll.LinkedList(None)
def test_construct_from_single_integer_fails():
with pytest.raises(TypeError):
ll.LinkedList(2)
def test_insert_single_value(base_llist):
base_llist.insert(4)
assert base_llist.__repr__() == "(4, 1, 2, 3)"
def test_pop(base_llist):
assert base_llist.pop() == 1
assert base_llist.__repr__() == "(2, 3)"
def test_size(base_llist):
assert base_llist.size() == 3
def test_search_val(base_llist):
searched_node = base_llist.search(2)
assert isinstance(searched_node, ll.Node)
assert searched_node.val == 2
def test_remove_node(base_llist):
base_llist.remove(base_llist.search(2))
assert base_llist.__repr__() == "(1, 3)"
def test_display(base_llist):
assert base_llist.display() == "(1, 2, 3)"