/* * Copyright 2014 (c) Anna Schumaker. * Test the filtering code */ #include #include "test.h" static void do_test_lowercase(const std::string &text, const std::string &lc) { test_equal(filter :: lowercase(text), lc); } static void test_lowercase() { do_test_lowercase(" ", ""); do_test_lowercase(" test \ text", "test text"); do_test_lowercase("test text", "test text"); do_test_lowercase("Test Text", "test text"); do_test_lowercase("Test? Text!", "test text"); do_test_lowercase("Test?123 Text!456", "test123 text456"); do_test_lowercase("Test?123 Text!456", "test123 text456"); do_test_lowercase("Test(text);123-456", "test text 123 456"); do_test_lowercase("Test((text));;123--456", "test text 123 456"); } 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_add() { 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) { std::set res; std::set::iterator it; filter :: search(text, res); test_equal(res.size(), (size_t)len); test :: begin(); it = res.begin(); for (unsigned int i = 0; i < len; i++) { check_equal(*it, ids[i]); it++; } test :: success(); } 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); } int main(int argc, char **argv) { run_test("Filter Lowercase Test", test_lowercase); run_test("Filter Add Test", test_add); run_test("Filter Search Test", test_search); return 0; }