Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3.  
  4. struct date{
  5. int day;
  6. int month;
  7. int year;
  8. };
  9.  
  10. //method stub for getDate
  11. struct date getDate(){
  12. //creates an empty date object
  13. struct date theDate;
  14. theDate.day = 1;
  15. theDate.month = 1;
  16. theDate.year = 2001;
  17. return theDate;
  18. }
  19.  
  20. //method stub for validDate
  21. bool validDate(struct date theDate){
  22. return false;
  23. }
  24.  
  25. //driver for getDate
  26. void testGetDate(){
  27. std::cout << "Entering tests for getDate()" << std::endl;
  28. //get the date
  29. struct date testDate = getDate();
  30. //boundary value tests for day
  31. assert(testDate.day > 0);
  32. assert(testDate.day < 31);
  33. std::cout << "All boundary value tests for day pass" << std::endl;;
  34. //boundary value tests for month
  35. assert(testDate.month > 0);
  36. assert(testDate.month < 12);
  37. std::cout << "All boundary value tests for month pass" << std::endl;
  38. //boundary value tests for year;
  39. assert(testDate.year > 1811);
  40. assert(testDate.year < 2012);
  41. std::cout << "All boundary value tests for year pass" << std::endl;
  42.  
  43. }
  44.  
  45. //driver for validDate
  46. void testValidDate(){
  47. std::cout << "Entering tests for validDate()" << std::endl;
  48.  
  49. struct date invalidDay;
  50. invalidDay.day = 0;
  51. invalidDay.month = 1;
  52. invalidDay.year = 2013;
  53. assert(validDate(invalidDay) == false);
  54. std::cout << "Test for invalid day passed" << std::endl;;
  55.  
  56. struct date invalidMonth;
  57. invalidMonth.day = 1;
  58. invalidMonth.month = 0;
  59. invalidMonth.year = 2013;
  60. assert(validDate(invalidMonth) == false);
  61. std::cout << "Test for invalid month passed" << std::endl;;
  62.  
  63.  
  64. struct date invalidYear;
  65. invalidYear.year = 0;
  66. invalidYear.day = 1;
  67. invalidYear.month = 1;
  68. assert(validDate(invalidYear) == false);
  69. std::cout << "Test for invalid year passed" << std::endl;;
  70.  
  71. struct date dateValidDayMonthYear;
  72. dateValidDayMonthYear.day = 1;
  73. dateValidDayMonthYear.month = 1;
  74. dateValidDayMonthYear.year = 2012;
  75. assert(validDate(dateValidDayMonthYear) == true);
  76. std::cout << "Test for valid date passed" << std::endl;; //because method stub always returns false, assertion should not pass
  77.  
  78. }
  79.  
  80. int main() {
  81. std::cout << "CS490 Chapter 13 Driver" << std::endl;
  82. std::cout << "By Kyle Peeler" << std::endl << std::endl;
  83. testGetDate();
  84. testValidDate();
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement