示例#1
0
 def test_insert_front_full_list(self):
     mylist = LinkedList()
     mylist.add(2)
     mylist.add(3)
     mylist.add(4)
     mylist.insert(0, 1)
     assert mylist.toList() == [1, 4, 3, 2]
     assert mylist.size() == 4
示例#2
0
 def test_many_items_first(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.reverse()
     mylist.reverse()
     assert mylist.pop(0) == 3
     assert mylist.size() == 2
示例#3
0
 def test_search(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.add(5)
     mylist.add(6)
     assert mylist.search(6)
     assert not mylist.search(4)
示例#4
0
 def test_insert_back_full_list(self):
     mylist = LinkedList()
     mylist.add(2)
     mylist.add(3)
     mylist.add(4)
     mylist.add(5)
     mylist.insert(-3, 1)
     assert mylist.toList() == [5, 1, 4, 3, 2]
     assert mylist.size() == 5
示例#5
0
 def test_remove_last(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.remove(1)
     assert mylist.toList() == [3, 2]
示例#6
0
 def test_remove_first(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.remove(3)
     assert mylist.toList() == [2, 1]
示例#7
0
 def test_many_duplicates(self):
     mylist = LinkedList()
     mylist.add(3)
     mylist.add(3)
     mylist.add(3)
     mylist.remove(3)
     assert mylist.toList() == [3, 3]
示例#8
0
 def test_many_items_middle(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     assert mylist.pop(-2) == 2
     assert mylist.size() == 2
示例#9
0
 def test_many_items_last(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     assert mylist.pop(-1) == 1
     assert mylist.size() == 2
示例#10
0
 def test_index(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     assert mylist.index(3) == 0
     assert mylist.index(2) == 1
     assert mylist.index(1) == 2
     assert mylist.index(4) == -1
示例#11
0
 def test_append(self):
     mylist = LinkedList()
     mylist.append(0)
     assert mylist.toList() == [0]
     mylist.add(1)
     assert mylist.toList() == [1, 0]
     mylist.append(5)
     assert mylist.toList() == [1, 0, 5]
示例#12
0
 def test_insert_back_one(self):
     mylist = LinkedList()
     mylist.add(2)
     mylist.insert(-1, 1)
     assert mylist.toList() == [1, 2]
     assert mylist.size() == 2
示例#13
0
 def test_non_integer_index(self):
     with pytest.raises(TypeError):
         mylist = LinkedList()
         mylist.insert(2.2, 1)
示例#14
0
 def test_reverse_empty(self):
     mylist = LinkedList()
     mylist.reverse()
     assert mylist.toList() == []
示例#15
0
 def test_clear(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.clear()
     assert mylist.size() == 0
     assert mylist.isEmpty()
     assert mylist.toList() == []
示例#16
0
 def test_size(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     assert mylist.size() == 2
示例#17
0
 def test_one_item(self):
     mylist = LinkedList()
     mylist.add(3)
     mylist.remove(3)
     assert mylist.isEmpty()
示例#18
0
 def test_empty_list(self):
     mylist = LinkedList()
     mylist.remove(1)
     assert mylist.isEmpty()
示例#19
0
 def test_toList(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     assert mylist.toList() == [3, 2, 1]
示例#20
0
 def test_empty_list(self):
     with pytest.raises(IndexError):
         mylist = LinkedList()
         mylist.pop()
示例#21
0
 def test_isEmpty(self):
     mylist = LinkedList()
     assert mylist.isEmpty()
示例#22
0
 def test_non_integer_pos(self):
     with pytest.raises(TypeError):
         mylist = LinkedList()
         mylist.add(3)
         mylist.pop(.4)
示例#23
0
 def test_reverse(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     assert mylist.toList() == [3, 2, 1]
     mylist.reverse()
     assert mylist.toList() == [1, 2, 3]
     mylist.reverse()
     assert mylist.toList() == [3, 2, 1]
示例#24
0
 def test_index_out_of_range_low(self):
     with pytest.raises(IndexError):
         mylist = LinkedList()
         mylist.add(2)
         mylist.pop(-100)
示例#25
0
 def test_missing_arg(self):
     with pytest.raises(ValueError):
         mylist = LinkedList()
         mylist.insert(1)
示例#26
0
 def test_one_item_last(self):
     mylist = LinkedList()
     mylist.add(2)
     assert mylist.pop(-1) == 2
     assert mylist.isEmpty()
示例#27
0
 def test_index_low(self):
     mylist = LinkedList()
     mylist.add(2)
     mylist.insert(-100, 1)
     assert mylist.toList() == [1, 2]
     assert mylist.size() == 2
示例#28
0
 def test_insert_middle_full_list(self):
     mylist = LinkedList()
     mylist.add(1)
     mylist.add(2)
     mylist.add(3)
     mylist.add(4)
     mylist.insert(2, 17)
     mylist.reverse()
     mylist.reverse()
     assert mylist.toList() == [4, 3, 17, 2, 1]
     assert mylist.size() == 5
示例#29
0
 def test_index_high(self):
     mylist = LinkedList()
     mylist.add(2)
     mylist.insert(100, 1)
     assert mylist.toList() == [2, 1]
     assert mylist.size() == 2
示例#30
0
 def test_insert_back_empty(self):
     mylist = LinkedList()
     mylist.insert(-1, 1)
     assert mylist.toList() == [1]
     assert mylist.size() == 1