Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Students.h"
- #include "../GoogleTest/googletest-master/googletest/include/gtest/gtest.h"
- using namespace std;
- int main() {
- std::cout << "Hello, World!" << std::endl;
- return 0;
- }
- ///
- ///
- void TEST(StudentsTest, SpecificationTesting)
- {
- auto STDNT = new Students();
- // Given a name, deletes the name and any phone number and grade associated with the id,
- // then removes the name:id record. Throws an out_of_range exception if name is not a key,
- // else no change.
- //void removeStudent(const std::string& name);
- bool cont = false;
- try { STDNT->removeStudent("ted"); }
- catch (const out_of_range& e)
- {
- cont = true;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- delete STDNT;
- // Removes each name in names from userIDs and removes any phone or grade with the id
- // associate with that name. Unlike removeStudent, does not throw any exceptions so the
- // list will be traversed. Returns the number of name in names removed.
- //unsigned int removeList(std::vector<std::string> names);
- STDNT = new Students();
- vector<string> ListOfNames {"a"};
- try { STDNT->removeList(ListOfNames); }
- catch (const exception& p)
- {
- FAIL();
- }
- delete STDNT;
- // Find the phone for a name using the associated id.
- // Throws an out_of_range exception if name not in the records or no phone associated
- // with name's id.
- //std::string phoneForName(const std::string& name);
- bool cont = true;
- STDNT = new Students();
- STDNT->addUser("bob",1);
- // Test that out_of_range exception is thrown for no phone associated
- try { STDNT->phoneForName("bob"); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- // Test that out_of_range exception is thrown for name not in records
- try { STDNT->phoneForName("dave"); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- delete STDNT;
- // Find the grade for a name using the associated id.
- // Throws an out_of_range exception if name not in the records or no grade associated
- // with name's id.
- //char gradeForName(const std::string& name);
- STDNT = new Students();
- try { STDNT->gradeForName("bob"); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- // Test that out_of_range exception is thrown for name not in records
- try { STDNT->gradeForName("dave"); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- delete STDNT;
- //Test ID for name exception throwing
- STDNT = new Students();
- try { STDNT->idForName("a"); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- // Test that out_of_range exception is thrown for name not in records
- try { STDNT->idForName("a")); }
- catch (const out_of_range& e)
- {
- cont = false;
- }
- catch (const exception& p)
- {
- FAIL();
- }
- if (cont)
- FAIL();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement