loa

Virtual machine for the Logic of Assumptions
git clone git://juanmeleiro.mat.br/loa
Log | Files | Refs

commit a9edbec57fdb9fc69af23507043fbf9fa76c15d0
parent 337437a00c033fd7b9e1bd278af9b66a64cb8c55
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date:   Wed,  8 May 2024 17:59:58 +0200

fix: Supid pop should use stupid pre-decrement

And stupid tests didn't catch it because stupid me didn't call them.

Diffstat:
Mcoding/stack.c | 2+-
Mcoding/stack.test.c | 7+++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/coding/stack.c b/coding/stack.c @@ -31,7 +31,7 @@ push(stack* s, void* p) void* pop(stack* s) { - return s->items[s->len--]; + return s->items[--s->len]; } void* diff --git a/coding/stack.test.c b/coding/stack.test.c @@ -1,4 +1,5 @@ #include <stdbool.h> +#include <assert.h> #include "stack.h" @@ -6,8 +7,8 @@ bool test_push_then_pop() { stack *s = new_stack(); - push(s, (void*)0x1); - return (pop(s) == (void*)0x1 && is_empty(s)); + push(s, (void*)0xfa); + return (pop(s) == (void*)0xfa && is_empty(s)); } bool @@ -21,5 +22,7 @@ test_push_then_peek() int main() { + assert(test_push_then_pop()); + assert(test_push_then_peek()); return 0; }