Technical test for a job interview.
at main 74 lines 1.8 kB view raw
1#include <iostream> 2#include <assert.h> 3#include "trie.hpp" 4#include "numeral_manager.hpp" 5 6void trie_test() 7{ 8 Trie t = Trie(); 9 10 assert(t.insert("hello") == true); 11 assert(t.search("hello") == true); 12 assert(t.insert("helloworld") == true); 13 assert(t.search("helloworld") == true); 14 assert(t.search("helll") == false); 15 assert(t.insert("hell") == true); 16 assert(t.insert("h") == true); 17 assert(t.search("h") == true); 18 19 assert(t.insert("hell") == false); 20 21 assert(t.remove("hello") == true); 22 assert(t.search("hello") == false); 23 assert(t.search("helloworld") == true); 24 assert(t.search("hell") == true); 25 26 assert(t.remove("h") == true); 27 assert(t.search("h") == false); 28 assert(t.search("hell") == true); 29 assert(t.search("helloworld") == true); 30 31 assert(t.remove("hells") == false); 32 assert(t.remove("tomatoes") == false); 33 34 assert(t.remove("helloworld") == true); 35 assert(t.search("helloworld") == false); 36 assert(t.search("hell") == true); 37 38 assert(t.remove("hell") == true); 39 assert(t.empty() == true); 40} 41 42void num_mgr_test(NumeralManager &mgr) 43{ 44 std::string str = "one hundred and eight"; 45 NumeralWord *nw = mgr.analyze(str); 46 //std::cout << nw->to_string() << " = " << nw->evaluate() << std::endl; 47 assert(nw->evaluate() == 108); 48 delete nw; 49 50 str = "two hundred thousand, four hundred forty"; 51 nw = mgr.analyze(str); 52 assert(nw != nullptr); 53 //std::cout << nw->to_string() << " = " << nw->evaluate() << std::endl; 54 assert(nw->evaluate() == 200440); 55} 56 57int main(int argc, char *argv[]) 58{ 59 trie_test(); 60 61 NumeralManager mgr = NumeralManager(); 62 mgr.language_setup(); 63 64 num_mgr_test(mgr); 65 66 if (argc > 1) 67 { 68 std::string str(argv[1]); 69 int num = mgr.analyze(str)->evaluate(); 70 std::cout << std::to_string(num) << std::endl; 71 } 72 73 return 0; 74}