aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-11-11 21:49:53 +0100
committerJulien Dessaux2021-11-11 21:49:53 +0100
commit98fe41748865e2b22b115627ef3297a671f3100d (patch)
treebf50a17515b96954d0acb26a523c99df65d4872f
parentSimplified some stack stack code (diff)
downloadnimfunge98-1.0.2.tar.gz
nimfunge98-1.0.2.tar.bz2
nimfunge98-1.0.2.zip
Fixed stack transfert sizing bug1.0.2
-rw-r--r--src/stack.nim2
-rw-r--r--tests/stack.nim6
2 files changed, 4 insertions, 4 deletions
diff --git a/src/stack.nim b/src/stack.nim
index 4565b5c..b100263 100644
--- a/src/stack.nim
+++ b/src/stack.nim
@@ -62,7 +62,7 @@ func Transfert*(toss: var Stack, soss: var Stack, n: int) =
## (aka begin) and '}' (aka end) stackstack commands
toss.height += n
if toss.height > toss.size:
- toss.size += 32
+ toss.size = toss.height
toss.data.setlen(toss.size)
for i in 1..min(soss.height, n):
toss.data[toss.height-i] = soss.data[soss.height-i]
diff --git a/tests/stack.nim b/tests/stack.nim
index ebbbe5d..bf02299 100644
--- a/tests/stack.nim
+++ b/tests/stack.nim
@@ -101,8 +101,8 @@ suite "Stack":
check some.data[2] == -4
check some.data[3] == 0
test "Transfert":
- var empty = NewStack()
- var empty2 = NewStack()
+ var empty = NewStack(size=12)
+ var empty2 = NewStack(size=7)
empty[].Transfert(empty2[], 4)
check empty.height == 4
check empty2.height == 0
@@ -111,7 +111,7 @@ suite "Stack":
check empty.data[2] == 0
check empty.data[3] == 0
empty[].Transfert(empty2[], 32)
- check empty.size == 64
+ check empty.size == 36
empty = NewStack()
var some = NewStack()
some[].Push(2)