-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(cherry picked from commit 6391f6e)
- Loading branch information
Showing
2 changed files
with
82 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,88 @@ | ||
discard """ | ||
output: '''true''' | ||
targets: "c js" | ||
""" | ||
|
||
import lists | ||
import std/[lists, sequtils] | ||
|
||
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" | ||
|
||
template main = | ||
block SinglyLinkedListTest1: | ||
var L: SinglyLinkedList[int] | ||
for d in items(data): L.prepend(d) | ||
for d in items(data): L.append(d) | ||
doAssert($L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]") | ||
|
||
doAssert(4 in L) | ||
|
||
block SinglyLinkedListTest2: | ||
var L: SinglyLinkedList[string] | ||
for d in items(data): L.prepend($d) | ||
doAssert($L == """["6", "5", "4", "3", "2", "1"]""") | ||
|
||
doAssert("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)) | ||
doAssert($L == "[6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6]") | ||
|
||
doAssert(4 in L) | ||
|
||
block SinglyLinkedRingTest1: | ||
var L: SinglyLinkedRing[int] | ||
L.prepend(4) | ||
doAssert($L == "[4]") | ||
L.prepend(4) | ||
|
||
doAssert($L == "[4, 4]") | ||
doAssert(4 in L) | ||
|
||
|
||
block DoublyLinkedRingTest1: | ||
var L: DoublyLinkedRing[int] | ||
L.prepend(4) | ||
doAssert($L == "[4]") | ||
L.prepend(4) | ||
|
||
doAssert($L == "[4, 4]") | ||
doAssert(4 in L) | ||
|
||
L.append(3) | ||
L.append(5) | ||
doAssert($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)) | ||
doAssert($L == "[]") | ||
doAssert(4 notin L) | ||
|
||
block tlistsToString: | ||
block: | ||
var l = initDoublyLinkedList[int]() | ||
l.append(1) | ||
l.append(2) | ||
l.append(3) | ||
doAssert $l == "[1, 2, 3]" | ||
block: | ||
var l = initDoublyLinkedList[string]() | ||
l.append("1") | ||
l.append("2") | ||
l.append("3") | ||
doAssert $l == """["1", "2", "3"]""" | ||
block: | ||
var l = initDoublyLinkedList[char]() | ||
l.append('1') | ||
l.append('2') | ||
l.append('3') | ||
doAssert $l == """['1', '2', '3']""" | ||
|
||
static: main() | ||
main() |