diff options
author | Julien Dessaux | 2021-10-04 20:10:21 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-10-04 20:10:21 +0200 |
commit | c9b3a999bd003b6489c5679c91c06ec48258e648 (patch) | |
tree | ffef54a52d86506cf422473a07de0b62d7aeb69e | |
parent | Improved readme (diff) | |
download | nimfunge98-c9b3a999bd003b6489c5679c91c06ec48258e648.tar.gz nimfunge98-c9b3a999bd003b6489c5679c91c06ec48258e648.tar.bz2 nimfunge98-c9b3a999bd003b6489c5679c91c06ec48258e648.zip |
Finished implementing the stackstack
Diffstat (limited to '')
-rw-r--r-- | src/stack.nim | 1 | ||||
-rw-r--r-- | src/stackStack.nim | 6 | ||||
-rw-r--r-- | tests/stack.nim | 2 | ||||
-rw-r--r-- | tests/stackStack.nim | 8 |
4 files changed, 17 insertions, 0 deletions
diff --git a/src/stack.nim b/src/stack.nim index eeef5cd..9ba3e24 100644 --- a/src/stack.nim +++ b/src/stack.nim @@ -73,6 +73,7 @@ func Transfert*(toss: var Stack, soss: var Stack, n: int) = soss.height = 0 func Discard*(s: var Stack, n: int) = + ## Implements a discard mechanism intended for use with the '}'(aka end) stackstack command s.height -= n if s.height < 0: s.height = 0 diff --git a/src/stackStack.nim b/src/stackStack.nim index 6d32c87..1bc89c0 100644 --- a/src/stackStack.nim +++ b/src/stackStack.nim @@ -25,6 +25,12 @@ func PushVector*(ss: var StackStack, v: tuple[x, y: int]) = func Clear*(ss: var StackStack) = ss.head[].Clear() +func Duplicate*(ss: var StackStack) = + ss.head[].Duplicate() + +func Swap*(ss: var StackStack) = + ss.head[].Swap() + func Begin*(ss: var StackStack, v: tuple[x, y: int]) = inc ss.height let soss = ss.head diff --git a/tests/stack.nim b/tests/stack.nim index cb49daf..cecdef9 100644 --- a/tests/stack.nim +++ b/tests/stack.nim @@ -110,6 +110,8 @@ suite "Stack": check empty.data[1] == 0 check empty.data[2] == 0 check empty.data[3] == 0 + empty[].Transfert(empty2[], 32) + check empty.size == 64 empty = NewStack() var some = NewStack() some[].Push(2) diff --git a/tests/stackStack.nim b/tests/stackStack.nim index 03650f8..9f3c176 100644 --- a/tests/stackStack.nim +++ b/tests/stackStack.nim @@ -22,6 +22,14 @@ suite "StackStack": empty[].Push(3) empty[].Clear() check empty[].Pop() == 0 + test "Duplicate": + var empty = NewStackStack() + empty[].Clear() + check empty[].Pop() == 0 + test "Swap": + var empty = NewStackStack() + empty[].Swap() + check empty[].Pop() == 0 test "Begin": var empty = NewStackStack() empty[].Begin((1, 2)) |