tests/core: Update filter test to new framework
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a9219d4f22
commit
583bb5d84b
|
@ -17,9 +17,9 @@ res += [ CoreTest("string", "string.cpp") ]
|
||||||
res += [ CoreTest("file", "file.cpp") ]
|
res += [ CoreTest("file", "file.cpp") ]
|
||||||
res += [ CoreTest("database", "database.cpp") ]
|
res += [ CoreTest("database", "database.cpp") ]
|
||||||
res += [ CoreTest("index", "index.cpp") ]
|
res += [ CoreTest("index", "index.cpp") ]
|
||||||
|
res += [ CoreTest("filter", "filter.cpp") ]
|
||||||
Return("res")
|
Return("res")
|
||||||
|
|
||||||
#test( "filter" )
|
|
||||||
#test( "idle" )
|
#test( "idle" )
|
||||||
#
|
#
|
||||||
#test( "tags/generic" )
|
#test( "tags/generic" )
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <core/filter.h>
|
#include <core/filter.h>
|
||||||
#include <tests/test.h>
|
#include "test.h"
|
||||||
|
|
||||||
static void do_test_add(const std::string &text, const std::string &lc)
|
static void do_test_add(const std::string &text, const std::string &lc)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ static void do_test_add(const std::string &text, const std::string &lc)
|
||||||
test_equal(filter :: add(text, i++), lc);
|
test_equal(filter :: add(text, i++), lc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_add()
|
static void test_addition()
|
||||||
{
|
{
|
||||||
do_test_add("It's dangerous to go alone! Take this...",
|
do_test_add("It's dangerous to go alone! Take this...",
|
||||||
"its dangerous to go alone take this");
|
"its dangerous to go alone take this");
|
||||||
|
@ -43,26 +43,20 @@ static void test_add()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::set<unsigned int>::iterator IT;
|
|
||||||
static unsigned int *IDS = NULL;
|
|
||||||
|
|
||||||
static unsigned int _do_test_search_compare(unsigned int i)
|
|
||||||
{
|
|
||||||
return (*IT++ == IDS[i]) ? LOOP_PASSED : LOOP_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_test_search(const std::string &text, unsigned int len,
|
static void do_test_search(const std::string &text, unsigned int len,
|
||||||
unsigned int *ids)
|
unsigned int *ids)
|
||||||
{
|
{
|
||||||
int init_values[] = { 1, 2, 3, 4, 5 };
|
int init_values[] = { 1, 2, 3, 4, 5 };
|
||||||
std::set<unsigned int> res(init_values, init_values + 5);
|
std::set<unsigned int> res(init_values, init_values + 5);
|
||||||
|
std::set<unsigned int>::iterator it;
|
||||||
|
|
||||||
filter :: search(text, res);
|
filter :: search(text, res);
|
||||||
test_equal(res.size(), (size_t)len);
|
test_equal(res.size(), (size_t)len);
|
||||||
|
|
||||||
IDS = ids;
|
it = res.begin();
|
||||||
IT = res.begin();
|
for (unsigned int i = 0; i < len; i++)
|
||||||
test_for_each(0, len, 1, _do_test_search_compare);
|
test_loop_equal(*it++, ids[i], i);
|
||||||
|
test_loop_passed();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_search()
|
static void test_search()
|
||||||
|
@ -88,9 +82,7 @@ static void test_search()
|
||||||
do_test_search("d", 3, res6);
|
do_test_search("d", 3, res6);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
DECLARE_UNIT_TESTS(
|
||||||
{
|
UNIT_TEST("Filter Addition", test_addition),
|
||||||
test :: run("Filter Add Test", test_add);
|
UNIT_TEST("Filter Search", test_search),
|
||||||
test :: run("Filter Search Test", test_search);
|
);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue