diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | choices.c | 6 | ||||
-rw-r--r-- | fzytest.c | 21 |
3 files changed, 26 insertions, 3 deletions
@@ -10,7 +10,7 @@ INSTALL_DATA=${INSTALL} -m 644 all: fzy fzytest -fzytest: fzytest.o match.o +fzytest: fzytest.o match.o choices.o $(CC) $(CFLAGS) $(CCFLAGS) -o $@ $^ test: fzytest @@ -80,10 +80,12 @@ double choices_getscore(choices_t *c, size_t n){ } void choices_prev(choices_t *c){ - c->selection = (c->selection + c->available - 1) % c->available; + if(c->available) + c->selection = (c->selection + c->available - 1) % c->available; } void choices_next(choices_t *c){ - c->selection = (c->selection + 1) % c->available; + if(c->available) + c->selection = (c->selection + 1) % c->available; } @@ -1,5 +1,7 @@ #include <stdio.h> + #include "match.h" +#include "choices.h" int testsrun = 0, testsfailed = 0, assertionsrun = 0; @@ -109,6 +111,23 @@ int test_positions_exact(){ return 0; } +int test_empty_choices(){ + choices_t choices; + choices_init(&choices); + assert(choices.size == 0); + assert(choices.available == 0); + assert(choices.selection == 0); + + choices_prev(&choices); + assert(choices.selection == 0); + + choices_next(&choices); + assert(choices.selection == 0); + + choices_free(&choices); + return 0; +} + void summary(){ printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed); } @@ -125,6 +144,8 @@ int main(int argc, char *argv[]){ runtest(test_positions_4); runtest(test_positions_exact); + runtest(test_empty_choices); + summary(); /* exit 0 if all tests pass */ |