ocarina/tests/core/filter.cpp

89 lines
2.5 KiB
C++

/*
* Copyright 2014 (c) Anna Schumaker.
* Test the filtering code
*/
#include <core/filter.h>
#include "test.h"
static void do_test_add(const std::string &text, const std::string &lc)
{
static unsigned int i = 0;
test_equal(filter :: add(text, i++), lc);
}
static void test_addition()
{
do_test_add("It's dangerous to go alone! Take this...",
"its dangerous to go alone take this");
do_test_add("DODONGO DISLIKES SMOKE.",
"dodongo dislikes smoke");
do_test_add("I am Error.",
"i am error");
do_test_add("Error knows a secret.",
"error knows a secret");
do_test_add("Hey, you pay, then you can open the chests!",
"hey you pay then you can open the chests");
do_test_add("And the Master Sword sleeps again... FOREVER!",
"and the master sword sleeps again forever");
do_test_add("Link checked the chest. Wow! This is a nice chest!",
"link checked the chest wow this is a nice chest");
do_test_add("Hey! Listen! Hey! Listen! Watch out!",
"hey listen hey listen watch out");
do_test_add("You killed the Deku Tree? How could you?!",
"you killed the deku tree how could you");
do_test_add("You've met with a terrible fate, haven't you?",
"youve met with a terrible fate havent you");
do_test_add("Believe in your strengths... Believe...",
"believe in your strengths believe");
do_test_add("Tingle! Tingle! Kooloo-Limpah!",
"tingle tingle kooloo limpah");
do_test_add("Well excuse me, Princess!",
"well excuse me princess");
}
static void do_test_search(const std::string &text, unsigned int len,
unsigned int *ids)
{
int init_values[] = { 1, 2, 3, 4, 5 };
std::set<unsigned int> res(init_values, init_values + 5);
std::set<unsigned int>::iterator it;
filter :: search(text, res);
test_equal(res.size(), (size_t)len);
it = res.begin();
for (unsigned int i = 0; i < len; i++)
test_loop_equal(*it++, ids[i], i);
test_loop_passed();
}
static void test_search()
{
unsigned int res1[] = {2, 3};
do_test_search("error", 2, res1);
unsigned int res2[] = {4, 5, 6, 8};
do_test_search("the", 4, res2);
unsigned int res3[] = {4, 6};
do_test_search("the ch", 2, res3);
do_test_search("the CH", 2, res3);
unsigned int res4[] = {4};
do_test_search("the ch y", 1, res4);
unsigned int res5[] = {};
do_test_search("unknown terms", 0, res5);
do_test_search("the chestZ", 0, res5);
unsigned int res6[] = {0, 1, 8};
do_test_search("d", 3, res6);
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Filter Addition", test_addition),
UNIT_TEST("Filter Search", test_search),
);