コード例 #1
0
  void testLexicon(){
    cout << "*** TESTING LEXICON ( buildLexicon() and isinLexicon() ) ***" << endl; 
    // Build lexicon
    cout << "Initializing lexicon..." << endl; 
    BogglePlayer bp;  
    string word1 = "this";
    string word2 = "that";
    string word3 = "whatever";
    set<string> wl; 
    auto insert = [&wl](string word){
       cout << "Inserting \"" << word << "\"... ";
       wl.insert(word);
       cout << "[DONE]" << endl; 
    };

    insert(word1); 
    insert(word2); 
    insert(word3);

    cout << "Building lexicon... "; 
    bp.buildLexicon(wl); 
    cout << "[DONE]" << endl; 

    auto checkWordTest = [&bp](string word, bool expected){
      cout << "Checking lexicon for \"" << word << "\"... ";
      if(bp.isInLexicon(word) && expected)
        cout << "[FOUND]" << endl; 
      else if(!bp.isInLexicon(word) && !expected)
        cout << "[NOT FOUND]" << endl;
      else if(bp.isInLexicon(word) && !expected)
        cout << "ERROR: \"" << word << "\" is not supposed to be in the lexicon" << endl;  
      else 
        cout << "ERROR: \"" << word << "\" is supposed to be in the lexicon" << endl;  
    };

    // Test words in lexicon. 
    checkWordTest(word1, true); 
    checkWordTest(word2, true);
    checkWordTest(word3, true); 

    // Test words not in lexicon.
    checkWordTest(string("thit"), false);
    checkWordTest(string("thas"), false); 
    checkWordTest(string("watever"), false); 
 
    cout << "Cleaning up test...";
    cout << "[DONE]" << endl << endl; 
  }
コード例 #2
0
ファイル: tester.cpp プロジェクト: jwl028/CSE100-P4
int main()
{
BogglePlayer player;
string custom1[]={"T","o","T"};
string custom2[]={"a","b","c"};
string custom3[]={"s","c","e"};
string** custom4;

custom4 = new string*[3];
for(unsigned int r=0; r<3;r++) {
  custom4[r] = new string[3];
}
for(int j = 0; j < 3; j++) {
  custom4[0][j] = custom1[j];
  custom4[1][j] = custom2[j];
  custom4[2][j] = custom3[j];
}
player.setBoard(3,3,custom4);
vector<int> test;
test = player.isOnBoard("BCE");

while(!test.empty()){
cout << test.back() << endl;
test.pop_back();
}



string tester = "TEST";
cout << tester.substr(1);
//for(int i = 0; i < 3; i++) {
//for(int j = 0; j < 3; j++) {
//cout << custom4[i][j] << " ";
//}
//cout << "/n";
//}
//}

const set<string>& listwords = "hello";
player.buildLexicon(listwords);

}
コード例 #3
0
ファイル: testboard.cpp プロジェクト: jiechuns/P4
int main(){
//BogglePlayer boggle;

/*  BaseBogglePlayer * p = new BogglePlayer();
  set<string> lex;
  string wordA("a");
  string wordX("x");
  lex.insert(wordA);
  lex.insert("z");
  string row0[] = {"D","C"};
  string row1[] = {"b","A"};
  string* board[] = {row0,row1};
  set<string> words;
  vector<int> locations;

  p->buildLexicon(lex);

  p->setBoard(2,2,board);
*/

BogglePlayer * boggle = new BogglePlayer();
//string row0[] = {"b","pp","l"};
string row0[] = {"le","g","e"};
//string row1[] = {"i","e","a"};
string row1[] = {"i","boa","bog"};
//string row2[] = {"r","e","p"};
string row2[] = {"r","d","j"};
//string** diceArray ={{"b","p","l"},{"i","q","a"},{"r","e","p"}};
string* diceArray[] = {row0, row1, row2};
boggle->setBoard(3, 3, diceArray);
std::vector<int> result = boggle->isOnBoard("boggleboard");
if(result.empty())
   	cout << "empty vector" << endl;
else
{
for(int i = 0; i < result.size(); i++)
	cout << "result is " << result[i] << endl;
}
return 0;
}
コード例 #4
0
int main (int argc, char* argv[]) {

  BogglePlayer * p = new BogglePlayer();
  //test getAllValid

   set<string> lex;
   string line;
  std::ifstream fword("boglex.txt",ios::binary);
  while(fword.good()){
    std::getline(fword,line);
    lex.insert(line);
  }
  fword.close();
   p->buildLexicon(lex);

//   std::ifstream f("brd.txt",ios::binary);
//   // int row=0;
//   // int col=0;
//   std::getline(f,line);
//   //row=std::stoi(line);
//   std::getline(f,line);
//   //col=std::stoi(line);

// string brd[20][23];
//   for(int i=0;i<20;i++){
//     for(int j=0;j<23;j++){
//       std::getline(f,line);
//       brd[i][j]=line;
//     }
//   }
//   f.close();
//   string* bd[20];
//   for(int i=0;i<20;i++){
//     bd[i]=brd[i];
//   }
//   p->setBoard(20,23,bd);
//   for(int i=0;i<20;i++){
//     for(int j=0;j<23;j++){
//       cout << p->board[i*23+j].letter<<" ";
//     }
//     cout<<endl;
//   }
//   std::vector<int> v;
//   v= p->isOnBoard("acidified");
//   for(int i=0;i<v.size();i++){
//     cout<<v[i]<<endl;
//   }
  //cout << "size " << p->isOnBoard("acidified").size() <<endl;
  // string wordA("a");
  // string wordX("x");
  // lex.insert(wordA);
  // lex.insert("aba");
  string row0[] = {"w"};
  string row1[] = {"e"};
  string row2[] = {"r"};
  string row3[] = {"e"};
  string* board[] = {row0,row1,row2,row3};
  set<string> words;
  // vector<int> locations;

  //p->buildLexicon(lex);
  //cout << "build" << endl;

  p->setBoard(4,1,board);
  // // for(int i=0;i<4;i++){
  // //   cout << p->board[i].letter << endl;
  // // }

  // if(p->isOnBoard("aba").size() == 3){
  //   cout << "found" << endl;
  // }

  // if(p->isInLexicon(wordX)) {
  //   std::cerr << "Apparent problem with isInLexicon #1." << std::endl;
  //   return -1;
  // }
  // if(!p->isInLexicon(wordA)) {
  //   std::cerr << "Apparent problem with isInLexicon #2." << std::endl;
  //   return -1;
  // }

  // if(p->isOnBoard(wordA).size() != 1) {
  //   std::cerr << "Apparent problem with isOnBoard #1." << std::endl;
  //   return -1;
  // }

  // locations.clear();
  // locations = p->isOnBoard(wordA);
  // if(locations.size() != 1 || locations[0] != 3) {
  //   std::cerr << "Apparent problem with isOnBoard #2." << std::endl;
  //   return -1;
  // }
  
  
  // if(!p->getAllValidWords(0,&words)) {
  //   std::cerr << "Apparent problem with getAllValidWords #1." << std::endl;
  //   return -1;
  // }
  // if(words.size() != 1 || words.count(wordA) != 1) {
  //   std::cerr << "Apparent problem with getAllValidWords #2." << std::endl;
  //   return -1;
  // }
  //set<string> words;
  p->getAllValidWords(0,&words);
  int j=0;
  for (std::set<string>::iterator it = words.begin() ; it != words.end(); ++it){
             j++;
             cout<<j<< " valid words "<<*it<<endl;
           }
  cout<<"total number"<<words.size()<<endl;

  delete p;
  return 0;

}
コード例 #5
0
  void testChkpt(){
    BogglePlayer bp; 
    string **board;
    board = new string*[4];
    for (size_t i=0;i<4;i++)
      board[i] = new string[4];
  
    // Initialize board  
    cout << "*** TESTING CHECKPOINT ( isOnBoard() and setBoard() ) ***" << endl; 
    cout << "Initializing board..." << endl;
    cout << "    s  t h r   " << endl; 
    cout << "    qu a v i   " << endl;
    cout << "    a  t d j   " << endl; 
    cout << "    c  p n e  " << endl << endl;      
 
    board[0][0] = "s";
    board[0][1] = "t";
    board[0][2] = "h";
    board[0][3] = "r";

    board[1][0] = "qu";
    board[1][1] = "a";
    board[1][2] = "v";
    board[1][3] = "i";

    board[2][0] = "a";
    board[2][1] = "t";
    board[2][2] = "d";
    board[2][3] = "j";

    board[3][0] = "c";
    board[3][1] = "p";
    board[3][2] = "n";
    board[3][3] = "e";

    bp.setBoard(4,4,board); 
	
    // Check for words.

    auto checkWord = [&bp](const string& word, bool should_be_found){
       cout << "Checking for word \"" << word << "\"... ";
       vector<int> path = bp.isOnBoard(word);
       // If vector comes up empty
       if(path.size() == 0){
         if(should_be_found == true)
           cerr << endl << "ERROR: \"" << word << "\" should be found on board." << endl;  
         else
           cout << "[NOT FOUND]" << endl;
       }
       // If vector does not come up empty. 
       else{
         if(should_be_found == false)
           cerr << endl << "ERROR: \"" << word << "\" should not be found on board." << endl;  
         else{
           cout << "[FOUND]" << endl; 
           cout << "Path to find \"" << word << "\" is: ";
           for(int coor: path){
	     cout << "(" << coor <<  ") ";
           }
           cout << endl; 
        }  
      }
    };

    // Words that exist
  
    checkWord("qua", true);
    checkWord("tsadi", true);
    checkWord("stat", true);
    checkWord("hadj", true);
    checkWord("asquat", true); 
    checkWord("aqua", true); 
 
    // Words that don't exist.
    checkWord("staqus", false);
    checkWord("tdnptat", false);
    checkWord("asdfghjkl", false);
    checkWord("pad", false);
    checkWord("vvvvvvvv", false);

    cout << "Cleaning up test...";
    for (size_t i=0;i<4;i++)
      delete[] board[i];
    delete[] board;
    cout << "[DONE]" << endl << endl; 
  }
コード例 #6
0
  void testSpeed(){
    cout << "*** TESTING WORD RETRIEVAL ( getAllValidWords() ) ***" << endl;
    BogglePlayer bp; 
     
    // Initialize board 
    cout << "Initializing board... ";
    std::ifstream brd ("brd.txt");
    if(!brd){
      cerr << "brd.txt does not exist. Aborting test." << endl; 
      return; 
    }

    unsigned int rows, cols;
    brd >> rows;
    brd >> cols;
    std::string** sbrd = new std::string*[rows];
    for (unsigned int r=0;r<rows;r++) {
      sbrd[r] = new std::string[cols];
      for (unsigned int c=0;c<cols;c++) {
        brd >> sbrd[r][c];
      }
    }
    bp.setBoard(rows, cols, sbrd);
    brd.close();
    cout << "[DONE]" << endl; 
 
    // Initialize lexicon
    cout << "Initializing lexicon... ";
    std::set<std::string> word_list;
    std::ifstream dict ("lex.txt");
    if(!dict){
      cerr << "lex.txt does not exist. Aborting test." << endl; 
      return; 
    }
  
    while (!dict.eof()) {
      std::string tmp;
      dict >> tmp;
      word_list.insert(tmp);
    }
  
    bp.buildLexicon(word_list);
    dict.close();
    cout << "[DONE]" << endl;    

    // Time word retrieval 
    cout << "Timing word retrieval using getAllValidWords(): ";
    std::set<std::string> words_found;
    clock_t start = clock(); 
    bool result = bp.getAllValidWords(2, &words_found);
    clock_t end = clock(); 
    float runtime = (float)(end-start) / CLOCKS_PER_SEC;

    cout << "Found " << words_found.size() << "/5450 words in " << runtime << " seconds." << endl;
    cout << "Return value when setBoard() and buildLexicon() previously called is: " << (result ? "true" : "false") << endl; 

    cout << "getAllValidWords() return value when only buildLexicon() called: "; 
    BogglePlayer bp2; 
    bp2.buildLexicon(word_list);
    std::set<std::string> words_found2; 
    result = bp2.getAllValidWords(2, &words_found2);
    cout << (result ? "true" : "false") << endl; 

    cout << "getAllValidWords() return value when only setBoard() called: "; 
    BogglePlayer bp3; 
    bp3.setBoard(rows, cols, sbrd);
    std::set<std::string> words_found3; 
    result = bp3.getAllValidWords(2, &words_found3);
    cout << (result ? "true" : "false") << endl;

    cout << "getAllValidWords() return value when neither buildLexicon() nor setBoard() are called: "; 
    BogglePlayer bp4; 
    std::set<std::string> words_found4; 
    result = bp4.getAllValidWords(2, &words_found4);
    cout << (result ? "true" : "false") << endl; 

    cout << "getAllValidWords() return value when buildLexicon() called on nonempty lexicon, setBoard() called on empty board: "; 
    BogglePlayer bp5;  
    std::string** empty_brd = new std::string*[0];
    for (unsigned int r=0;r<0;r++) {
      empty_brd[r] = new std::string[0];
    } 
    bp5.setBoard(0,0,empty_brd);
    bp5.buildLexicon(word_list);
    std::set<std::string> words_found5;    
    result = bp5.getAllValidWords(2, &words_found5);
    cout << (result ? "true" : "false");  
    cout << ", Words found: " << words_found5.size() << endl;  

    cout << "getAllValidWords() return value when buildLexicon() called on empty lexicon, setBoard() called on nonempty board: "; 
    BogglePlayer bp6; 
    bp6.setBoard(rows, cols, sbrd);
    std::set<std::string> empty_wordlist;
    bp6.buildLexicon(empty_wordlist);
    std::set<std::string> words_found6;  
    result = bp6.getAllValidWords(2, &words_found6);
    cout << (result ? "true" : "false"); 
    cout << ", Words found: " << words_found6.size() << endl;  

    cout << "getAllValidWords() return value when buildLexicon() called on empty lexicon, setBoard() called on empty board: "; 
    BogglePlayer bp7; 
    bp6.setBoard(0,0,empty_brd);
    bp6.buildLexicon(empty_wordlist);
    std::set<std::string> words_found7;  
    result = bp6.getAllValidWords(2, &words_found7);
    cout << (result ? "true" : "false");  
    cout << ", Words found: " << words_found7.size() << endl;  

    cout << "Cleaning up test... ";
    for (unsigned int r=0;r<rows;r++)
      delete[] sbrd[r];
    delete[] sbrd;

    for(unsigned int r=0; r<0; r++)
      delete[] empty_brd[r];
    delete[] empty_brd; 

    cout << "[DONE]" << endl << endl; 
  }