Browse code

Add test for large input

John Hawthorn authored on 18/01/2017 02:15:47
Showing 1 changed files

... ...
@@ -1,6 +1,8 @@
1
+#define _GNU_SOURCE
2
+#include <malloc.h>
3
+#include <signal.h>
1 4
 #include <stdio.h>
2 5
 #include <string.h>
3
-#include <signal.h>
4 6
 
5 7
 #include "../config.h"
6 8
 #include "match.h"
... ...
@@ -279,6 +281,32 @@ void test_choices_unicode() {
279 281
 	choices_destroy(&choices);
280 282
 }
281 283
 
284
+void test_choices_large_input() {
285
+	choices_t choices;
286
+	choices_init(&choices);
287
+
288
+	int N = 100000;
289
+	char *strings[N];
290
+
291
+	for(int i = 0; i < N; i++) {
292
+		asprintf(&strings[i], "%i", i);
293
+		choices_add(&choices, strings[i]);
294
+	}
295
+
296
+	choices_search(&choices, "12");
297
+
298
+	/* Must match `seq 0 99999 | grep '.*1.*2.*' | wc -l` */
299
+	assert(choices.available == 8146);
300
+
301
+	assert_streq(choices_get(&choices, 0), "12")
302
+
303
+	for(int i = 0; i < N; i++) {
304
+		free(strings[i]);
305
+	}
306
+
307
+	choices_destroy(&choices);
308
+}
309
+
282 310
 void summary() {
283 311
 	printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed);
284 312
 }
... ...
@@ -310,6 +338,7 @@ int main(int argc, char *argv[]) {
310 338
 	runtest(test_choices_2);
311 339
 	runtest(test_choices_without_search);
312 340
 	runtest(test_choices_unicode);
341
+	runtest(test_choices_large_input);
313 342
 
314 343
 	summary();
315 344