interpret/test/test_kjv.c
2023-03-14 22:04:21 -07:00

33 lines
1.0 KiB
C

#include "../src/kjvcount.h"
#include <stdio.h>
#include <inttypes.h> /* C99 */
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
int main(void) {
int success = EXIT_SUCCESS;
errno = 0; /* `errno` is not set correctly to 0 in some debug situations. */
struct kjvcount count = kjvcount();
struct kjvset_table set = kjv_set();
fprintf(stderr, "%zu total words, %s.\n",
count.words.total, kjvcount_to_string(&count));
if(kjvcount_is_empty(&count)) goto catch;
kjv_set_add(&set, &count,
(union kjvcite){ .book = Genesis, .chapter = 1, .verse = 1 });
kjv_set_add(&set, &count,
(union kjvcite){ .book = Genesis, .chapter = 1, .verse = 2 });
kjv_set_add(&set, &count,
(union kjvcite){ .book = Genesis, .chapter = 1, .verse = 1 });
fprintf(stderr, "%zu of which: %s.\n", count.words.set, kjv_set_to_string(&set));
assert(count.words.total == 789633);
assert(count.words.set == 39);
goto finally;
catch:
success = EXIT_FAILURE, perror("kjv");
finally:
kjv_set_(&set);
kjvcount_(&count);
return success;
}