Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include <iostream>
  2. #include "Students.h"
  3. #include "../GoogleTest/googletest-master/googletest/include/gtest/gtest.h"
  4. using namespace std;
  5.  
  6. int main() {
  7. std::cout << "Hello, World!" << std::endl;
  8. return 0;
  9. }
  10.  
  11. ///
  12. ///
  13. void TEST(StudentsTest, SpecificationTesting)
  14. {
  15. auto STDNT = new Students();
  16.  
  17. // Given a name, deletes the name and any phone number and grade associated with the id,
  18. // then removes the name:id record. Throws an out_of_range exception if name is not a key,
  19. // else no change.
  20. //void removeStudent(const std::string& name);
  21. bool cont = false;
  22.  
  23. try { STDNT->removeStudent("ted"); }
  24. catch (const out_of_range& e)
  25. {
  26. cont = true;
  27. }
  28. catch (const exception& p)
  29. {
  30. FAIL();
  31. }
  32.  
  33. if (cont)
  34. FAIL();
  35.  
  36. delete STDNT;
  37. // Removes each name in names from userIDs and removes any phone or grade with the id
  38. // associate with that name. Unlike removeStudent, does not throw any exceptions so the
  39. // list will be traversed. Returns the number of name in names removed.
  40. //unsigned int removeList(std::vector<std::string> names);
  41. STDNT = new Students();
  42. vector<string> ListOfNames {"a"};
  43.  
  44. try { STDNT->removeList(ListOfNames); }
  45.  
  46. catch (const exception& p)
  47. {
  48. FAIL();
  49. }
  50.  
  51. delete STDNT;
  52. // Find the phone for a name using the associated id.
  53. // Throws an out_of_range exception if name not in the records or no phone associated
  54. // with name's id.
  55.  
  56. //std::string phoneForName(const std::string& name);
  57. bool cont = true;
  58.  
  59. STDNT = new Students();
  60.  
  61. STDNT->addUser("bob",1);
  62.  
  63. // Test that out_of_range exception is thrown for no phone associated
  64. try { STDNT->phoneForName("bob"); }
  65. catch (const out_of_range& e)
  66. {
  67. cont = false;
  68. }
  69. catch (const exception& p)
  70. {
  71. FAIL();
  72. }
  73.  
  74. if (cont)
  75. FAIL();
  76.  
  77. // Test that out_of_range exception is thrown for name not in records
  78. try { STDNT->phoneForName("dave"); }
  79. catch (const out_of_range& e)
  80. {
  81. cont = false;
  82. }
  83. catch (const exception& p)
  84. {
  85. FAIL();
  86. }
  87.  
  88. if (cont)
  89. FAIL();
  90.  
  91. delete STDNT;
  92.  
  93. // Find the grade for a name using the associated id.
  94. // Throws an out_of_range exception if name not in the records or no grade associated
  95. // with name's id.
  96.  
  97. //char gradeForName(const std::string& name);
  98. STDNT = new Students();
  99. try { STDNT->gradeForName("bob"); }
  100. catch (const out_of_range& e)
  101. {
  102. cont = false;
  103. }
  104. catch (const exception& p)
  105. {
  106. FAIL();
  107. }
  108.  
  109. if (cont)
  110. FAIL();
  111.  
  112. // Test that out_of_range exception is thrown for name not in records
  113. try { STDNT->gradeForName("dave"); }
  114. catch (const out_of_range& e)
  115. {
  116. cont = false;
  117. }
  118. catch (const exception& p)
  119. {
  120. FAIL();
  121. }
  122.  
  123. if (cont)
  124. FAIL();
  125.  
  126. delete STDNT;
  127.  
  128. //Test ID for name exception throwing
  129.  
  130. STDNT = new Students();
  131.  
  132. try { STDNT->idForName("a"); }
  133. catch (const out_of_range& e)
  134. {
  135. cont = false;
  136. }
  137. catch (const exception& p)
  138. {
  139. FAIL();
  140. }
  141.  
  142. if (cont)
  143. FAIL();
  144.  
  145. // Test that out_of_range exception is thrown for name not in records
  146. try { STDNT->idForName("a")); }
  147. catch (const out_of_range& e)
  148. {
  149. cont = false;
  150. }
  151. catch (const exception& p)
  152. {
  153. FAIL();
  154. }
  155.  
  156. if (cont)
  157. FAIL();
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement