tlists.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. discard """
  2. output: '''true'''
  3. """
  4. import lists
  5. const
  6. data = [1, 2, 3, 4, 5, 6]
  7. block SinglyLinkedListTest1:
  8. var L: SinglyLinkedList[int]
  9. for d in items(data): L.prepend(d)
  10. for d in items(data): L.append(d)
  11. assert($L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]")
  12. assert(4 in L)
  13. block SinglyLinkedListTest2:
  14. var L: SinglyLinkedList[string]
  15. for d in items(data): L.prepend($d)
  16. assert($L == """["6", "5", "4", "3", "2", "1"]""")
  17. assert("4" in L)
  18. block DoublyLinkedListTest1:
  19. var L: DoublyLinkedList[int]
  20. for d in items(data): L.prepend(d)
  21. for d in items(data): L.append(d)
  22. L.remove(L.find(1))
  23. assert($L == "[6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]")
  24. assert(4 in L)
  25. block SinglyLinkedRingTest1:
  26. var L: SinglyLinkedRing[int]
  27. L.prepend(4)
  28. assert($L == "[4]")
  29. L.prepend(4)
  30. assert($L == "[4, 4]")
  31. assert(4 in L)
  32. block DoublyLinkedRingTest1:
  33. var L: DoublyLinkedRing[int]
  34. L.prepend(4)
  35. assert($L == "[4]")
  36. L.prepend(4)
  37. assert($L == "[4, 4]")
  38. assert(4 in L)
  39. L.append(3)
  40. L.append(5)
  41. assert($L == "[4, 4, 3, 5]")
  42. L.remove(L.find(3))
  43. L.remove(L.find(5))
  44. L.remove(L.find(4))
  45. L.remove(L.find(4))
  46. assert($L == "[]")
  47. assert(4 notin L)
  48. echo "true"