示例#1
0
def test_LinkedListWithTwoNode():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)

    assert linkedList.head.value == 1
    assert linkedList.tail.value == 2
示例#2
0
文件: Vertex.py 项目: ximet/algoset
class Vertex:
    def __init__(self, value):
        if value == None:
            raise AttributeError('Problem with value: value is empty')
        self.value = value
        self.edges = LinkedList()

    def addEdge(self, edge):
        self.edges.append(edge)
        return self
示例#3
0
def test_reverseLinkedList():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)
    linkedList.append(3)
    linkedList.reverse()
    counter = 3
    for node in linkedList:
        assert node.value == counter
        counter -= 1
示例#4
0
def test_searchValueLinkedList():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)
    assert linkedList.search(1).value == 1
    assert linkedList.search(2).value == 2
    assert linkedList.search(1).next.value == 2
    assert linkedList.search(3) == None
示例#5
0
class Stack:
    def __init__(self):
        self.stack = LinkedList()

    def isEmpty(self):
        return self.stack.head == None

    def push(self, value):
        self.stack.prepend(value)

    def pop(self):
        removedItem = self.stack.deleteHead()
        if removedItem == None:
            return None
        return removedItem.value

    def peek(self):
        if self.isEmpty():
            return None
        return self.stack.head.value
示例#6
0
def test_LinkedListRemoveSecondValue():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)
    linkedList.remove(2)
    assert linkedList.head.value == 1
    assert linkedList.head.value == linkedList.tail.value
示例#7
0
def test_iteration():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)
    linkedList.append(3)
    counter = 1
    for node in linkedList:
        assert node.value == counter
        counter += 1
示例#8
0
文件: Vertex.py 项目: ximet/algoset
 def __init__(self, value):
     if value == None:
         raise AttributeError('Problem with value: value is empty')
     self.value = value
     self.edges = LinkedList()
示例#9
0
 def __init__(self):
     self.stack = LinkedList()
示例#10
0
def test_searchInEmptyLinkedList():
    linkedList = LinkedList()
    assert linkedList.search(2) == None
示例#11
0
def test_LinkedListWithTwoValues():
    linkedList = LinkedList()
    linkedList.append(1)
    linkedList.append(2)
    assert linkedList.size() == 2
示例#12
0
def test_emptyLinkedList():
    linkedList = LinkedList()
    assert linkedList.size() == 0
示例#13
0
def test_linkedListWithOneNode():
    linkedList = LinkedList()
    linkedList.append(1)

    assert linkedList.head.value == 1
示例#14
0
def test_LinkedListRemoveFirstNode():
    linkedList = LinkedList()
    linkedList.append(1)
    assert linkedList.head.value == 1
    linkedList.remove(1)
    assert linkedList.head == None