Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help DEBUGGING so the TEST CASES will run. This is my third time asking for help, please someone help me with correct coding.

I need help DEBUGGING so the TEST CASES will run. This is my third time asking for help, please someone help me with correct coding. TEST CASES: class DestructorTester {
public:
static unsigned int getCount(){
return count;
}
static unsigned int getTotalCopyCalls(){
return totalCopyCalls;
}
DestructorTester(){
count++;
}
DestructorTester(const DestructorTester& obj){
count++;
totalCopyCalls++;
}
void operator=(const DestructorTester& obj){
// Not a constructor, so no new object is created here. No need to increment count.
totalCopyCalls++;
}
~DestructorTester(){
count--;
}
private:
static unsigned int count;
static unsigned int totalCopyCalls;
};
unsigned int DestructorTester::count =0;
unsigned int DestructorTester::totalCopyCalls =0;
//This helps with testing, do not modify.
bool checkTest(int testNum, int& correct, int whatItShouldBe, int whatItIs){
if (whatItShouldBe == whatItIs){
correct++;
cout "Passed " testNum endl;
return true;
}
else {
cout "***Failed test " testNum "***" endl " Output was " whatItIs endl " Output should have been " whatItShouldBe endl;
cout "The unit test checker is closing down the program now due to a failed test" endl;
exit(1);
return false;
}
}
//This helps with testing, comment it in when ready, but do not modify the code.
bool checkTest(int testNum, int& correct, string whatItShouldBe, string whatItIs){
if (whatItShouldBe == whatItIs){
correct++;
cout "Passed " testNum endl;
return true;
}
else {
if (whatItShouldBe ==""){
cout "***Failed test " testNum "***" endl " Output was " whatItIs endl " Output should have been blank. " endl;
}
else {
cout "***Failed test " testNum "***" endl " Output was " whatItIs endl " Output should have been " whatItShouldBe endl;
}
cout "The unit test checker is closing down the program now due to a failed test" endl;
exit(1);
return false;
}
}
//This helps with testing, do not modify.
bool checkTestMemory(int testNum, int& correct, int whatItShouldBe, int whatItIs){
if (whatItShouldBe == whatItIs){
correct++;
cout "Passed " testNum endl;
return true;
}
else {
cout "***Failed test " testNum ". You have a memory leak. " endl;
return false;
}
}
//This helps with testing, do not modify.
bool checkTestMemory2(int testNum, int& correct, int beforeTotalCopyCalls, int afterTotalCopyCalls){
if (beforeTotalCopyCalls == afterTotalCopyCalls){
correct++;
cout "Passed " testNum endl;
return true;
}
else {
cout "***Failed test " testNum "You didn't move the pointers around, you copied values "(afterTotalCopyCalls - beforeTotalCopyCalls)" times." endl;
return false;
}
}
//This helps with testing, do not modify.
bool testGetFifthElement(){
int testNum =1;
int correct =0;
cout "--------testGetFifthElement Tests--------" endl;
SinglyLinkedList* si = new SinglyLinkedList;
for (int i =10; i 20; i++){
si->pushBack(i);
}
//Test just to make sure the data went in the list.
checkTest(testNum++, correct, "10111213141516171819", si->getStringFromList()); //1
//Test retrieving item.
int item = si->getFifthElement();
checkTest(testNum++, correct, 14, item); //2
delete si;
si = new SinglyLinkedList;
for (int i =10; i 15; i++){
si->pushBack(i);
}
//Test just to make sure the data went in the list.
checkTest(testNum++, correct, "1011121314", si->getStringFromList()); //3
//Test retrieving item.
item = si->getFifthElement();
checkTest(testNum++, correct, 14, item); //4
delete si;
si = new SinglyLinkedList;
for (int i =10; i 14; i++){
si->pushBack(i);
}
//Test just to make sure the data went in the list.
checkTest(testNum++, correct, "10111213", si->getStringFromList()); //5
//Try to access out of bounds.
string caughtError ="";
try {
item = si->getFifthElement();
}
catch (std::out_of_range&){
caughtError = "caught";
}
checkTest(testNum++, correct, "caught", caughtError); //6
delete si;
SinglyLinkedList* ss = new SinglyLinkedList;
ss->pushBack("Multi Pass");
ss->pushBack("Lelu Dallas");
ss->pushBack("BIG BADA BOOM");
ss->pushBack("Bruce Willis");
ss->pushBack("Fried Chicken");
ss->pushBack("EEEAAAAAAAeeeaaaaaEEeeAAAEEaaaaAA");
checkTest(testNum++, correct, "Fried Chicken", ss->getFifthElement()); //8
delete ss;
return testNum -1== correct;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago