コード例 #1
0
ファイル: bogtest.cpp プロジェクト: DieterJoubert/CSE100
int main (int argc, char* argv[]) {

  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);

  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(wordX).size() > 0) {
    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;
  }

  cout << "ALL PASSED" << endl;

  delete p;
  return 0;

}
コード例 #2
0
ファイル: bogtest.cpp プロジェクト: hongmincschen/CSE_100
int main (int argc, char* argv[]) {

  BaseBogglePlayer * p = new BogglePlayer();
  set<string> lex;
  string wordA("boy");
  string wordX("xwer");
  lex.insert(wordA);
  lex.insert("cat");
  string row0[] = {"D","C"};
  string row1[] = {"b","A"};
  string row3[] = {"oy","at"};
  string* board[] = {row0,row1,row3};
  set<string> words;
  vector<int> locations;

  p->buildLexicon(lex);

  p->setBoard(3,2,board);

  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(wordX).size() > 0) {
    std::cerr << "Apparent problem with isOnBoard #1." << std::endl;
    return -1;
  }
  locations.clear();
  locations = p->isOnBoard("DC");
  if(locations.size() != 2 || locations[0] != 0) {
    std::cerr << "Apparent problem with isOnBoard #2." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard("d");
  if(locations.size() != 1 || locations[0] != 0) {
    std::cerr << "Apparent problem with isOnBoard #3." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard("bA");
  if(locations.size() != 2 || locations[0] != 2) {
    std::cerr << "Apparent problem with isOnBoard #4." << std::endl;
    return -1;
  }

  locations.clear();
  locations = p->isOnBoard(wordA);
  cout << "locations size: " << locations.size() << "locations[0]: "<< locations[0] <<endl;
  if( locations.size() != 2 || locations[0] != 2 ) {
    std::cerr << "Apparent problem with isOnBoard #5." << std::endl;
    return -1;
  }
  
  
  if(!p->getAllValidWords(0,&words)) {
    std::cerr << "Apparent problem with getAllValidWords #1." << std::endl;
    return -1;
  };
  cout<<"Word size: " << words.size()<<endl;
  for (auto it1 = words.cbegin(); it1 != words.cend(); ++it1){
    std::cout << "Valid Words: " << *it1 << std::endl;
  }
  if(words.size() != 1 || words.count(wordA) != 1) {
    std::cerr << "Apparent problem with getAllValidWords #2." << std::endl;
    return -1;
  }

  delete p;
  return 0;

}