interpret/test/test_kjv.c

46 lines
1.3 KiB
C
Raw Normal View History

2023-03-22 04:11:56 -04:00
#include "../src/kjvcite.h"
2022-12-27 15:28:04 -05:00
#include <stdio.h>
#include <inttypes.h> /* C99 */
#include <stdlib.h>
2022-12-27 16:55:58 -05:00
#include <assert.h>
2023-03-10 23:06:11 -05:00
#include <errno.h>
2022-12-27 15:28:04 -05:00
int main(void) {
2022-12-27 16:48:45 -05:00
int success = EXIT_SUCCESS;
2023-03-10 23:06:11 -05:00
errno = 0; /* `errno` is not set correctly to 0 in some debug situations. */
2023-03-22 04:11:56 -04:00
size_t no_total, no_set = 0;
struct kjvcount_table count = kjv_count(&no_total);
2023-03-15 01:02:22 -04:00
struct kjvset_table set = kjv_set();
2023-03-22 04:11:56 -04:00
union kjvcite verse = { .book = Genesis, .chapter = 1, .verse = 1 };
2023-03-15 01:02:22 -04:00
fprintf(stderr, "%zu total words, %s.\n",
2023-03-22 04:11:56 -04:00
no_total, kjv_count_to_string(&count));
if(!no_total) goto catch;
switch(kjv_set_add(&set, verse)) {
case TABLE_ERROR: goto catch;
case TABLE_PRESENT: assert(0); break;
case TABLE_ABSENT: no_set += kjv_count_get(&count, verse); break;
}
verse.verse = 2;
switch(kjv_set_add(&set, verse)) {
case TABLE_ERROR: goto catch;
case TABLE_PRESENT: assert(0); break;
case TABLE_ABSENT: no_set += kjv_count_get(&count, verse); break;
}
verse.verse = 1;
switch(kjv_set_add(&set, verse)) {
case TABLE_ERROR: goto catch;
case TABLE_PRESENT: break;
case TABLE_ABSENT: assert(0); break;
}
fprintf(stderr, "%zu of which: %s.\n", no_set, kjv_set_to_string(&set));
assert(no_total == 789633);
assert(no_set == 39);
2022-12-27 16:48:45 -05:00
goto finally;
catch:
success = EXIT_FAILURE, perror("kjv");
finally:
2023-03-15 01:02:22 -04:00
kjv_set_(&set);
2023-03-22 04:11:56 -04:00
kjv_count_(&count);
2022-12-27 16:48:45 -05:00
return success;
2022-12-27 15:28:04 -05:00
}