1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- discard """
- output: '''true'''
- """
- import lists
- const
- data = [1, 2, 3, 4, 5, 6]
- block SinglyLinkedListTest1:
- var L: SinglyLinkedList[int]
- for d in items(data): L.prepend(d)
- for d in items(data): L.append(d)
- assert($L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]")
- assert(4 in L)
- block SinglyLinkedListTest2:
- var L: SinglyLinkedList[string]
- for d in items(data): L.prepend($d)
- assert($L == """["6", "5", "4", "3", "2", "1"]""")
- assert("4" in L)
- block DoublyLinkedListTest1:
- var L: DoublyLinkedList[int]
- for d in items(data): L.prepend(d)
- for d in items(data): L.append(d)
- L.remove(L.find(1))
- assert($L == "[6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]")
- assert(4 in L)
- block SinglyLinkedRingTest1:
- var L: SinglyLinkedRing[int]
- L.prepend(4)
- assert($L == "[4]")
- L.prepend(4)
- assert($L == "[4, 4]")
- assert(4 in L)
- block DoublyLinkedRingTest1:
- var L: DoublyLinkedRing[int]
- L.prepend(4)
- assert($L == "[4]")
- L.prepend(4)
- assert($L == "[4, 4]")
- assert(4 in L)
- L.append(3)
- L.append(5)
- assert($L == "[4, 4, 3, 5]")
- L.remove(L.find(3))
- L.remove(L.find(5))
- L.remove(L.find(4))
- L.remove(L.find(4))
- assert($L == "[]")
- assert(4 notin L)
- echo "true"
|