132 lines
3.9 KiB
C++
132 lines
3.9 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#include <filter.h>
|
|
#include <print.h>
|
|
#include <vector>
|
|
|
|
std::string quotes [] = {
|
|
"What heroes like best is themselves.",
|
|
"The sun rose slowly, as if wasn't sure it was worth all the effort",
|
|
"Of course I'm sane, when trees start talking to me, I don't talk back",
|
|
"Darkness isn't the opposite of light, it's simply its absence",
|
|
"Time passed, which, basically, is its job",
|
|
"Million-to-one chances crop up nine times out of ten",
|
|
"CATS ARE NICE",
|
|
"Death isn't cruel - merely terribly, terribly good at his job",
|
|
"Thunder rolled ... it rolled a six",
|
|
"DROP THE SCYTHE, AND TURN AROUND SLOWLY",
|
|
"Time is like a drug. Too much of it kills you",
|
|
"Gravity is a habit that is hard to shake off",
|
|
"You do not ask people like that what they are thinking about in case "
|
|
"they turn around very slowly and say 'You'",
|
|
"Do unto others before they do unto you",
|
|
"Not a man to mince words. People, yes. But not words",
|
|
"An elf's strength lay in persuading others they were weak",
|
|
"May you live in interesting times",
|
|
"WITH HIM HERE, EVEN UNCERTAINTY IS UNCERTAIN. AND I'M NOT SURE EVEN "
|
|
"ABOUT THAT",
|
|
"I AM DEATH, NOT TAXES. I TURN UP ONLY ONCE",
|
|
"All tribal myths are true, for a given value of 'true'",
|
|
"The Truth Shall Make Ye Fret",
|
|
"When you look into the abyss, it's not supposed to wave back",
|
|
"I have no use for people who have learned the limits of the possible",
|
|
"Speak softly and employ a huge man with a crowbar",
|
|
"Truly, the leopard can change his shorts",
|
|
"+++Divide By Cucumber Error, Please Reinstall Universe And Reboot+++",
|
|
"+++Whoops! Here comes the cheese! +++",
|
|
"Bring out yer dead, bring out yer living dead",
|
|
"1. ALL FUNGI ARE EDIBLE. 2. SOME FUNGI ARE NOT EDIBLE MORE THAN ONCE.",
|
|
"A lot of farming is about manure",
|
|
"I am very attached to my fingers, and I like to think of them as attached to me",
|
|
"There be a lot o' men who became heroes cuz they wuz too scared tae run",
|
|
"If only the pawns united, make talked the rooks round, the whole board "
|
|
"could've been a republic in a dozen moves",
|
|
"Always remember that the crowd that applauds your coronation is the same "
|
|
"crowd that will applaud your beheading. People like a show.",
|
|
};
|
|
|
|
static const unsigned int num_quotes = sizeof(quotes) / sizeof(std::string);
|
|
|
|
void print_index(Database<IndexEntry> &db)
|
|
{
|
|
db.print_keys();
|
|
for (unsigned int i = db.first(); i <= db.last(); i = db.next(i)) {
|
|
print("index[%s] = ", db[i].primary_key.c_str());
|
|
db[i].print();
|
|
print("\n");
|
|
}
|
|
print("\n");
|
|
}
|
|
|
|
void test_search(const std::string &text)
|
|
{
|
|
std::set<unsigned int> results;
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
filter :: search(text, results);
|
|
|
|
print("Search for: \"%s\" returned %u matches:\n",
|
|
text.c_str(), results.size());
|
|
|
|
for (it = results.begin(); it != results.end(); it++)
|
|
print("\t%s\n", quotes[*it].c_str());
|
|
print("\n");
|
|
}
|
|
|
|
void test_lowercase(const std::string &text)
|
|
{
|
|
std::string res = filter :: to_lowercase(text);
|
|
print("Lowercasing: \"%s\" returned: \"%s\"\n", text.c_str(), res.c_str());
|
|
}
|
|
|
|
void test_0()
|
|
{
|
|
for (unsigned int i = 0; i < num_quotes; i++)
|
|
filter :: add(quotes[i], i);
|
|
print_index(filter :: get_index());
|
|
filter :: print_cache_stats();
|
|
print("\n");
|
|
}
|
|
|
|
void test_1()
|
|
{
|
|
test_search("");
|
|
test_search("Rincewind");
|
|
test_search("Rincewind Twoflower Luggage");
|
|
test_search("the");
|
|
test_search("the is");
|
|
test_search("THE IS");
|
|
test_search("th i");
|
|
test_search("th i even");
|
|
test_search("Th/i-eVEn");
|
|
test_search("whoops");
|
|
filter :: print_cache_stats();
|
|
print("\n");
|
|
}
|
|
|
|
void test_2()
|
|
{
|
|
test_lowercase("");
|
|
test_lowercase("Rincewind");
|
|
test_lowercase("Rincewind Twoflower Luggage");
|
|
test_lowercase("the");
|
|
test_lowercase("the is");
|
|
test_lowercase("THE IS");
|
|
test_lowercase("th i");
|
|
test_lowercase("th i even");
|
|
test_lowercase("Th/i-eVen");
|
|
test_lowercase("whoops");
|
|
test_lowercase("WHOOPS");
|
|
filter :: print_cache_stats();
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test_0();
|
|
test_1();
|
|
test_2();
|
|
|
|
return 0;
|
|
}
|