From 618be61d1b9d83c624e001ca3c2c6b251e8e53fb Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 17 Jan 2017 18:15:47 -0800 Subject: Add test for large input --- test/fzytest.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/fzytest.c b/test/fzytest.c index 3786cd7..7c9d1cd 100644 --- a/test/fzytest.c +++ b/test/fzytest.c @@ -1,6 +1,8 @@ +#define _GNU_SOURCE +#include +#include #include #include -#include #include "../config.h" #include "match.h" @@ -279,6 +281,32 @@ void test_choices_unicode() { choices_destroy(&choices); } +void test_choices_large_input() { + choices_t choices; + choices_init(&choices); + + int N = 100000; + char *strings[N]; + + for(int i = 0; i < N; i++) { + asprintf(&strings[i], "%i", i); + choices_add(&choices, strings[i]); + } + + choices_search(&choices, "12"); + + /* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */ + assert(choices.available == 8146); + + assert_streq(choices_get(&choices, 0), "12") + + for(int i = 0; i < N; i++) { + free(strings[i]); + } + + choices_destroy(&choices); +} + void summary() { printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed); } @@ -310,6 +338,7 @@ int main(int argc, char *argv[]) { runtest(test_choices_2); runtest(test_choices_without_search); runtest(test_choices_unicode); + runtest(test_choices_large_input); summary(); -- cgit v1.2.3