summaryrefslogtreecommitdiff
path: root/fzytest.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-09-14 20:26:09 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-09-14 20:53:52 -0700
commit8417e77d7b60c220f28ac25f2812ea79509dfd99 (patch)
tree8d9144a964976084e58a29ab6e38e629fb5e8c9b /fzytest.c
parent854c2bdd159b5ca1d10db2603fcb448ebe8fdcba (diff)
Fix divide by zero on empty choices list
Diffstat (limited to 'fzytest.c')
-rw-r--r--fzytest.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/fzytest.c b/fzytest.c
index cc20d0e..285975a 100644
--- a/fzytest.c
+++ b/fzytest.c
@@ -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 */