diff options
Diffstat (limited to 'tests/accept/run/tlists.nim')
-rw-r--r-- | tests/accept/run/tlists.nim | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/accept/run/tlists.nim b/tests/accept/run/tlists.nim index e69de29bb..7d5379945 100644 --- a/tests/accept/run/tlists.nim +++ b/tests/accept/run/tlists.nim @@ -0,0 +1,66 @@ +discard """ + output: '''true''' +""" + +import lists + +const + data = [1, 2, 3, 4, 5, 6] + +block SinglyLinkedListTest1: + var L: TSinglyLinkedList[int] + for d in items(data): L.prepend(d) + assert($L == "[6, 5, 4, 3, 2, 1]") + + assert(4 in L) + +block SinglyLinkedListTest2: + var L: TSinglyLinkedList[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: TDoublyLinkedList[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: TSinglyLinkedRing[int] + L.prepend(4) + assert($L == "[4]") + L.prepend(4) + + assert($L == "[4, 4]") + assert(4 in L) + + +block DoublyLinkedRingTest1: + var L: TDoublyLinkedRing[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" + |