1
Fork 0
turbonss/cxxmph/mph_table_test.cc

38 lines
910 B
C++
Raw Normal View History

2010-11-05 04:17:08 +02:00
#include <algorithm>
#include <cassert>
2010-10-28 03:17:09 +03:00
#include <string>
#include <vector>
2011-05-16 02:47:42 +03:00
#include "mph_table.h"
2010-10-28 03:17:09 +03:00
using std::string;
using std::vector;
2010-11-05 08:40:15 +02:00
using cxxmph::SimpleMPHTable;
int main(int argc, char** argv) {
2010-10-28 05:45:43 +03:00
srand(1);
2010-10-28 03:17:09 +03:00
vector<string> keys;
keys.push_back("davi");
keys.push_back("paulo");
keys.push_back("joao");
keys.push_back("maria");
keys.push_back("bruno");
2010-10-29 03:53:40 +03:00
keys.push_back("paula");
keys.push_back("diego");
keys.push_back("diogo");
keys.push_back("algume");
2011-05-16 02:47:42 +03:00
SimpleMPHTable<string> mph_table;
assert(mph_table.Reset(keys.begin(), keys.end()));
vector<int> ids;
2010-10-28 03:17:09 +03:00
for (vector<int>::size_type i = 0; i < keys.size(); ++i) {
2011-05-16 02:47:42 +03:00
ids.push_back(mph_table.index(keys[i]));
2010-10-28 03:17:09 +03:00
cerr << " " << *(ids.end() - 1);
}
cerr << endl;
sort(ids.begin(), ids.end());
2010-10-28 03:17:09 +03:00
for (vector<int>::size_type i = 0; i < ids.size(); ++i) assert(ids[i] == static_cast<vector<int>::value_type>(i));
}