cfd8ca8d43
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
75 lines
1.9 KiB
C
75 lines
1.9 KiB
C
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/filter.h>
|
|
#include <tests/test.h>
|
|
|
|
const gchar *test_strings[] = {
|
|
/* 0 */ "koji kondo",
|
|
/* 1 */ "hyrule symphony",
|
|
/* 2 */ "kokiri forest",
|
|
/* 3 */ "hyrule field",
|
|
/* 4 */ "hyrule castle",
|
|
/* 5 */ "lon lon ranch",
|
|
/* 6 */ "kakariko village",
|
|
/* 7 */ "death mountain",
|
|
/* 8 */ "zoras domain",
|
|
/* 9 */ "gerudo valley",
|
|
/* 10 */ "ganondorf",
|
|
/* 11 */ "princess zelda",
|
|
/* 12 */ "ocarina medley",
|
|
/* 13 */ "the legend of zelda medley",
|
|
};
|
|
|
|
#define NUM_STRINGS (sizeof(test_strings) / sizeof(gchar *))
|
|
|
|
static void test_filter()
|
|
{
|
|
struct set res = SET_INIT();
|
|
unsigned int i;
|
|
|
|
filter_init();
|
|
for (i = 0; i < NUM_STRINGS; i++) {
|
|
filter_add(test_strings[i], i);
|
|
} test_loop_passed();
|
|
|
|
/* Search for a word! */
|
|
filter_search("hyrule", &res);
|
|
test_equal(set_size(&res), 3);
|
|
test_equal(set_has(&res, 1), (bool)true); /* hyrule symphony */
|
|
test_equal(set_has(&res, 3), (bool)true); /* hyrule field */
|
|
test_equal(set_has(&res, 4), (bool)true); /* hyrule castle */
|
|
|
|
/* A second search should clear the set. */
|
|
filter_search("zelda", &res);
|
|
test_equal(set_size(&res), 2);
|
|
test_equal(set_has(&res, 11), (bool)true); /* princess zelda */
|
|
test_equal(set_has(&res, 13), (bool)true); /* the legend of zelda medley */
|
|
|
|
/* Partial word search. */
|
|
filter_search("ko", &res);
|
|
test_equal(set_size(&res), 2);
|
|
test_equal(set_has(&res, 0), (bool)true); /* koji kondo */
|
|
test_equal(set_has(&res, 2), (bool)true); /* kokiri forest */
|
|
|
|
/* Multiple word search. */
|
|
filter_search("hyrule field", &res);
|
|
test_equal(set_size(&res), 1);
|
|
test_equal(set_has(&res, 3), (bool)true); /* hyrule field */
|
|
|
|
/* Search for unknown word. */
|
|
filter_search("field termina", &res);
|
|
test_equal(set_size(&res), 0);
|
|
|
|
/* Search for empty string. */
|
|
filter_search("", &res);
|
|
test_equal(set_size(&res), 0);
|
|
|
|
filter_deinit();
|
|
set_deinit(&res);
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Filter", test_filter),
|
|
);
|