コード例 #1
0
TEST(NameExistsTest, NameExistsTest1){
  Students* students = new Students();
  uint id = 0;
  std::string quinn = "Quinn";
  std::string phone = "801";
  char grade = 'A';

  students->addUser("Quinn", id);
  students->addUser("Andre", 1);
  students->addUser("Jim", 2);
  students->addUser("Bob", 3);
  students->addPhoneNumbers(students->idForName("Quinn"), "801");
  students->addGrade(id, 'A');

  EXPECT_TRUE(students->fullRecord(quinn, id, phone, grade));
  EXPECT_EQ(4, students->numberOfNames());
  EXPECT_TRUE(students->nameExists("Quinn"));

  students->removeStudent("Quinn");

  EXPECT_EQ(3, students->numberOfNames());
  EXPECT_FALSE(students->nameExists("Quinn"));
  EXPECT_FALSE(students->fullRecord(quinn, id, phone, grade));

  delete students;
}
コード例 #2
0
TEST(AddUser, AddUserTest3){
  Students* students = new Students();
  int user_count = 0;
  for(; user_count < 10; user_count++)
    students->addUser("Student " + std::to_string(user_count), user_count);

  EXPECT_EQ(user_count, students->numberOfNames());
  
  students->removeStudent("Student 0");
  students->removeStudent("Student 1");
  user_count -= 2;

  EXPECT_EQ(user_count, (int)students->numberOfNames());

  Students* moreStudents = new Students(); 
  moreStudents->addUser("Jim", 11);
  moreStudents->addUser("Jim", 12);
  
  EXPECT_NE(2, (int)moreStudents->numberOfNames());    //should be 2 instead of 1. 
  //it is possible to have 2 names with different IDs.
  //however, when 2 names with different IDs are present, 
  //the map only updates the numberOfNames  once.
  EXPECT_EQ(12, moreStudents->idForName("Jim"));
 
  moreStudents->removeStudent("Jim");
 
  //since Jim was in 2 spots in the map, he should be deleted at both spots?
  //this is true, and the count is correct here.  When Jim is deleted, he gets
  //deleted at both spots.
  EXPECT_EQ(0, (int)moreStudents->numberOfNames());

  delete students;
  delete moreStudents;
}
コード例 #3
0
TEST(RemoveListTest, RemoveListTest1){
  Students* students = new Students();

  std::vector<std::string> names;
  names.push_back("Andre");
  names.push_back("Jim");
  names.push_back("Quinn");

  //students->addUser("Andre", 0);
  //students->addUser("Jim", 1);
  //students->addUser("Quinn", 2);
  for(int i = 0; i < 3; i++){
    students->addUser(names[i], i);
  }
  students->addUser("Joe", 4);
  students->addUser("Billy", 5);
  students->addUser("Bob", 6);
  
  EXPECT_EQ(6, students->numberOfNames());
  EXPECT_TRUE(students->nameExists("Quinn"));
  EXPECT_TRUE(students->nameExists("Andre"));
  EXPECT_TRUE(students->nameExists("Jim"));
  
  students->removeList(names);
  
  EXPECT_FALSE(students->nameExists("Quinn"));
  EXPECT_FALSE(students->nameExists("Andre"));
  EXPECT_FALSE(students->nameExists("Jim"));
  EXPECT_EQ(3, students->numberOfNames());
  
  delete students;
}
コード例 #4
0
TEST(AddUser, AddUserTest5){
  uint id = 12;
  std::string andre = "Andre";
  std::string aPhone = "801-867-5309";
  char aGrade = 'A';

  std::string quinn = "Quinn";
  std::string qPhone = "801-555-5555";
  char qGrade = 'B';

  // Shows what happens when two users have the same ID
  Students* students = new Students();
  students->addUser(andre, id);
  students->addPhoneNumbers(students->idForName(andre), aPhone);
  students->addGrade(students->idForName(andre), aGrade);

  students->addUser(quinn, id);
  students->addPhoneNumbers(students->idForName(quinn), qPhone);
  students->addGrade(students->idForName(quinn), qGrade);

  EXPECT_TRUE(students->fullRecord(andre, id, aPhone, aGrade));
  EXPECT_TRUE(students->fullRecord(quinn, id, qPhone, qGrade));
  EXPECT_NE(students->gradeForName(quinn), students->gradeForName(andre));
  EXPECT_NE(students->phoneForName(quinn), students->phoneForName(andre));
  // 2 different students should not have the same ID in the first place,
  // here, 2 different students with the same ID have the same grade when each grade
  // should be different. This must mean that when we add 2 users with the same ID
  // the first one is overwritten.  

  delete students;
}
コード例 #5
0
/*
 * fullRecord()
 */
TEST(FullRecordTest, FullRecordTest1){
  Students* students = new Students();
  std::string bob = "Bob";
  std::string phoneNumber = "KL5-3226";
  char grade = 'D';
  uint id = 2;
  uint new_id = 5;

  students->addUser(bob, id);
  students->addGrade(students->idForName(bob), grade);
  students->addPhoneNumbers(students->idForName(bob), phoneNumber);
  students->fullRecord(bob, id, phoneNumber, grade);
  EXPECT_TRUE(students->fullRecord(bob, id, phoneNumber, grade));

  grade = 'C';
  students->addGrade(students->idForName(bob), grade);
  EXPECT_TRUE(students->fullRecord(bob, id, phoneNumber, grade));

  // Even though there is a new guy with the name of Bob, there should still be a full record of the old
  // Bob in there
  students->addUser(bob, new_id);
  EXPECT_TRUE(students->fullRecord(bob, id, phoneNumber, grade));
  
  delete students;
}
コード例 #6
0
TEST(GradeForName, GradeForNameTest2){
  Students* students = new Students();
  students->addUser("Quinn", 0);
  students->addGrade(0, ' ');

  EXPECT_EQ(' ', students->gradeForName("Quinn"));

  students->addUser("Andre", 1);
  students->addGrade(1, ' ');

  EXPECT_EQ(students->gradeForName("Quinn"), students->gradeForName("Andre"));

  delete students;
}
コード例 #7
0
TEST(AddPhoneNumber, AddPhoneNumberTest2){
  Students* students = new Students();
  students->addPhoneNumbers(0, "fsadhfdkasdfhl");
  students->addPhoneNumbers(0, "801");
  students->addUser("Hi", 0);
  EXPECT_EQ("801", students->phoneForName("Hi"));

}
コード例 #8
0
//specific tests for AddUser that dont really have to do with edge cases.
TEST(AddUser, AddUserTest2){
  Students* students = new Students();
  // Overwrites the user's place
  students->addUser("Quinn", 0);
  students->addUser("Andre", 0);
  EXPECT_EQ(0, students->idForName("Andre"));

  students->addUser("David Johnson", 3);
  EXPECT_EQ(3, students->idForName("David Johnson"));
  //here, the test fails because the AddUser method is a little messed up.
  //we want to have only 1 person with the ID of 0, no matter the name.
  //instead we get Quinn, who was added first, then Andre was added in his place
  //and finally David Johnson was added last.  When overwritting an ID, the count 
  //of how many people on the map is not updated properly.
  EXPECT_EQ(2, students->numberOfNames());

  delete students;
}
コード例 #9
0
TEST(AddPhoneNumber, AddPhoneNumberTest1){
  Students* students = new Students();
  students->addUser("Mr. Plow", 12121);          //Simpsons reference?
  students->addPhoneNumbers(12121, "801-KL5-3226");

  EXPECT_EQ("801-KL5-3226", students->phoneForName("Mr. Plow"));

  delete students;
}
コード例 #10
0
TEST(NameExistsTest, NameExistsTest2){
  Students* students = new Students();
  uint id = 0;
  uint id2 = 1;
  std::string quinn = "Quinn";
  std::string andre = "Andre";
  std::string phone = "801";
  std::string phone2 = "435";
  char grade = 'A';
  char grade2 = 'A';

  students->addUser(quinn, id);
  students->addUser(andre, id2);
  EXPECT_EQ(id, students->idForName(quinn));
  EXPECT_EQ(id2, students->idForName(andre));
  
  students->addPhoneNumbers(id, phone);
  students->addPhoneNumbers(id2, phone2);

  EXPECT_EQ(phone, students->phoneForName(quinn));
  EXPECT_EQ(phone2, students->phoneForName(andre));

  students->addGrade(id, grade);
  students->addGrade(id2, grade2);

  EXPECT_EQ(grade, students->gradeForName(quinn));
  EXPECT_EQ(grade2, students->gradeForName(andre));
  EXPECT_TRUE(students->fullRecord(quinn, id, phone, grade));
  EXPECT_TRUE(students->fullRecord(andre, id2, phone2, grade2));
  EXPECT_TRUE(students->nameExists(quinn));
  EXPECT_TRUE(students->nameExists(andre));

  std::string bill = "Bill";
  uint id3 = 3;
  students->addUser("Bill", id3);
  students->addPhoneNumbers(id3, phone);
  students->addGrade(id3, grade);

  EXPECT_TRUE(students->fullRecord(bill, id3, phone, grade));
  EXPECT_TRUE(students->nameExists(bill));

  delete students;
}
コード例 #11
0
/*
 * gradeForName
 */
TEST(GradeForName, GradeForNameTest1){
  Students* students = new Students();
  students->addUser("Billy", 0);
  students->addGrade(0, 'C');
  EXPECT_EQ('C', students->gradeForName("Billy"));
 
  EXPECT_THROW(students->gradeForName("John"), std::out_of_range);

  students->addUser("Quinn", 1);
  students->addUser("Joe", 2);
  students->addGrade(1, 'D');
  students->addGrade(1, 'A');
  students->addGrade(2, 'z');

  EXPECT_EQ('A', students->gradeForName("Quinn"));
  EXPECT_EQ('z', students->gradeForName("Joe"));

  delete students;
}
コード例 #12
0
//Edge case tests for AddUser
TEST(AddUser, AddUserTest1){
  Students* students = new Students();
  students->addUser("Quinn", 0);
  EXPECT_EQ(0, students->idForName("Quinn"));
  
  //we should get a positive number because it is an unsigned int on the map.
  students->addUser("Andre", -1);
  EXPECT_EQ(true, students->idForName("Andre") > 0);

  //not sure if this should throw an exception or not.
  students->addUser("", 5);
  EXPECT_EQ(5, students->idForName("")); 

  //exception?
  students->addUser(" ", 2);
  EXPECT_EQ(2, students->idForName(" "));

  delete students;
}
コード例 #13
0
TEST(AddUser, AddUserTest6){
  Students* students = new Students();
  
  students->addUser("Quinn", 0);
  students->addUser("Quinn", 0);

  EXPECT_EQ(1, students->numberOfNames());

  delete students;
}
コード例 #14
0
TEST(AddPhoneNumber, AddPhoneNumberTest3){
  Students* students = new Students();

  students->addUser("Steve", 21);
  EXPECT_EQ(21, students->idForName("Steve"));

  students->addPhoneNumbers(students->idForName("Steve"), "##");
  EXPECT_EQ("##", students->phoneForName("Steve"));
 
  students->addUser("Quinn", 0);
  students->addUser("Andre", 1);

  students->addPhoneNumbers(0, "");
  students->addPhoneNumbers(0, " ");
  students->addPhoneNumbers(1, "907");
  EXPECT_EQ(" ", students->phoneForName("Quinn"));
  EXPECT_EQ("907", students->phoneForName("Andre"));
  EXPECT_NE(students->phoneForName("Quinn"), students->phoneForName("Andre"));
  EXPECT_EQ(3, students->numberOfNames());
  delete students;
}
コード例 #15
0
TEST(AddUser, AddUserTest4){
  Students* students = new Students();
  students->addUser("Andre", 12);
  students->addUser("Andre", 13);

  EXPECT_EQ(13, students->idForName("Andre"));
  EXPECT_EQ(1, students->numberOfNames());

  students->addUser("Quinn", 21);
  students->addUser("Quinn", 23);
  EXPECT_EQ(23, students->idForName("Quinn"));
  EXPECT_EQ(2, students->numberOfNames());

  // No two users should ever have the same ID
  students->addUser("Quinn", 13);
  EXPECT_EQ(2, students->numberOfNames());
  EXPECT_EQ(13, students->idForName("Quinn"));
  //here, 2 users have the same ID with different names.
  
  EXPECT_NE(students->idForName("Andre"), students->idForName("Quinn")); 
  
  delete students;
}
コード例 #16
0
TEST(RemoveStudentTest, RemoveStudentTest1){
  Students* students = new Students();
  students->addUser("Jimmy", 5);
  students->removeStudent("Jimmy");
  EXPECT_EQ(0, students->numberOfNames());

  EXPECT_THROW(students->removeStudent("Billy"), std::out_of_range);

  
  // TODO: Figure this out
  std::vector<std::string> someNames();
  //someNames.push_back("Jimmy");
  //someNames.push_back("Bobby");
  
  //EXPECT_NO_THROW(students->removeList(someNames));

  delete students;
}