Advertisement
Guest User

main final

a guest
Mar 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #include "DynamicArray.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. //*********** addElements Function is Tested ***********
  10.  
  11. DynamicArray Darr(1);
  12. Darr.addElement(1);
  13. Darr.addElement(2);
  14. Darr.addElement(3);
  15. Darr.addElement(4);
  16. Darr.addElement(5);
  17. if (Darr.getArraySize() == 8)
  18. {
  19. cout << "Correct Result" << endl;
  20. cout << "array Size after expansion is : 8" << endl << endl;
  21. }
  22. else
  23. {
  24. cout << "Your addElement Function is not correct" << endl;
  25. cout << "Your arraySize after Expansion is : " << Darr.getArraySize() << endl;
  26. cout << "Expected Output : 8 " << endl << endl;
  27. }
  28. //*********** Constructor with invalid input is Tested ***********
  29. DynamicArray Darr2(0);
  30. if (Darr2.getArraySize() == 1)
  31. {
  32. cout << "Correct Result" << endl;
  33. cout << "array Size after given wrong value (less than one) : 1" << endl << endl;
  34. }
  35. else
  36. {
  37. cout << "Your constrcutor is not Correct" << endl;
  38. cout << "The arraySize should be at least One" << endl << endl;
  39. }
  40.  
  41. //*********** Method with invalid input is Tested ***********
  42. DynamicArray Darr3(3);
  43. Darr3.addElement(20);
  44. Darr3.addElement(22);
  45. if (Darr3.getArraySize() == 3) {
  46. cout << "Correct Result" << endl;
  47. cout << "array Size is after given a wrong value (less than actual numOfElements) : 3" << endl << endl;
  48. }
  49. else {
  50. cout << "Your Constrcutor is not Correct" << endl;
  51. cout << "The value passed for arraySize should be bigger than actual numOfElements" << endl << endl;
  52. }
  53.  
  54. //*********** toString Function is Tested ***********
  55. DynamicArray Darr4(1);
  56. Darr4.addElement(1);
  57. Darr4.addElement(2);
  58. Darr4.addElement(3);
  59. string s = Darr4.toString();
  60. string str1 = "1,2,3";
  61.  
  62. if (s == str1) {
  63. cout << "Correct Result" << endl;
  64. cout << "Elements of array :1,2,3" << endl << endl;
  65. }
  66. else {
  67. cout << "Result is incorrect " << endl;
  68. cout << "your function prints:";
  69. cout << s << endl;
  70. cout << " But, Expected output should be:" << str1 << endl << endl;
  71.  
  72. }
  73.  
  74. //*********** Copy Constructor is Tested ***********
  75. DynamicArray Darr5(1);
  76. Darr5.addElement(10);
  77. DynamicArray Darr6 = Darr5;
  78. Darr6.addElement(100);
  79. Darr6.addElement(1000);
  80. string s1 = Darr5.toString();
  81. string output1 = "10";
  82. string s2 = Darr6.toString();
  83. string output2 = "10,100,1000";
  84. //if(Darr.getnumOfElements() == 3 && Darr.getarraySize() == 4)
  85. if (s1 == output1 && s2 == output2) {
  86. cout << "Correct Result" << endl;
  87. cout << "First array has " << Darr5.toString() << endl;
  88. cout << "Copied array after modification has " << Darr6.toString() << endl << endl;
  89. }
  90. else {
  91. cout << "Result is incorrect " << endl;
  92. cout << "First array has " << Darr5.toString() << " should have: 10" << endl;
  93. cout << "Copied array after modification has " << Darr5.toString() << " should have: 10,100,1000";
  94.  
  95.  
  96. }
  97.  
  98. system("pause");
  99. return 0;
  100.  
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement