summary refs log tree commit diff stats
path: root/tests/stdlib/tlists.nim
blob: 7d53799457b331538fca6b175144342f4ad631ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-co
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"
pan class="o">, error:variant break-unless error-exit? $print [error caught: ] err 10/newline } ] # Callee function that we catch exceptions in must always return using a # continuation. def f raise-exception?:bool -> result:error-or:num [ local-scope load-inputs { break-unless raise-exception? # throw/raise result <- merge 0/error, [error will robinson!] return-continuation-until-mark 999/exception-tag, result } # 'normal' return; still uses the continuation mark result <- merge 1/value, 34 return-continuation-until-mark 999/exception-tag, result # dead code just to avoid errors result <- merge 1/value, 0 return result ]