update dict
[QFreeRecite.git] / src / core / Tester.cpp
blob9aaabcd1fc96b4e38fef0614071c552bbfca0430
1 #include "Debug.h"
2 #include "Tester.h"
3 #include "ConfigHolder.h"
4 #include <fstream>
7 namespace freeRecite {
9 Tester::Tester() {
10 std::ifstream ifs(configHolder.keyFile().c_str());
11 std::string tmpWord;
13 while(ifs.good()) {
14 std::getline(ifs, tmpWord);
15 if(!tmpWord.empty())
16 errWords.insert(tmpWord);
18 ifs.close();
21 Tester::~Tester() {
22 D_OUTPUT("~Tester()\n");
23 std::ofstream ofs(configHolder.keyFile().c_str());
24 std::set<std::string>::const_iterator itr = errWords.begin();
25 while(itr != errWords.end()) {
26 ofs << *itr << std::endl;
27 ++itr;
29 ofs.close();
32 bool Tester::load(time_t initID) {
33 if( loadWords(initID,true) ) {
34 wordList = new WordList(words.size(),configHolder.t_list());
35 return true;
36 }else {
37 return false;
41 void Tester::test(bool result) {
42 if(result) {
43 if(wordList->status() == 0)
44 ++score;
45 wordList->pass();
46 } else {
47 if( wordList->status() == 0)
48 errWords.insert(getWord());
49 wordList->lose();
53 } //End of namespace freeRecite