108 lines
No EOL
3.1 KiB
C++
108 lines
No EOL
3.1 KiB
C++
// Corey Williams
|
|
// COP3530 01Z
|
|
//Project 5
|
|
|
|
//10. Write a member function to check whether two singly linked lists have the same contents
|
|
|
|
#include <iostream>
|
|
#include "intSLList.h"
|
|
|
|
using namespace std;
|
|
|
|
void testOutput(bool result, bool expResult) {
|
|
if (result == expResult) { cout << "TEST PASS"; }
|
|
else { cout << "TEST FAIL"; }
|
|
cout << " Expected: " << expResult << " | Actual : " << result << endl;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
IntSLList listA;
|
|
IntSLList listB;
|
|
int arrA[5] = { 2, 24, -1, 88, 3 };
|
|
|
|
|
|
//Test 1: Test two linked lists that are equivalent elements and same length - Expected result is TRUE (1)
|
|
//Loads arrA into both linked lists
|
|
for (int i = 0; i < 5; i++) {
|
|
listA.addToTail(arrA[i]);
|
|
listB.addToTail(arrA[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), true);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
|
|
|
|
//Test 2: Test two linked lists that are unequal but the same length - Expected result is FALSE (0)
|
|
int arrB[5] = { 2, 24, -1, 88, 5 };
|
|
for (int i = 0; i < 5; i++) {
|
|
listB.addToTail(arrB[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), false);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
|
|
|
|
//Test 3: Test two linked lists that are unequal and the second list is longer - Expected result is FALSE (0)
|
|
int arrC[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
|
for (int i = 0; i < sizeof(arrC)/sizeof(arrC[0]); i++) {
|
|
listB.addToTail(arrC[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), false);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
|
|
|
|
//Test 4: Test two linked lists that are unequal and the second list is shorter - Expected result is FALSE (0)
|
|
int arrD[3] = { 1, 2, 3 };
|
|
for (int i = 0; i < sizeof(arrD) / sizeof(arrD[0]); i++) {
|
|
listB.addToTail(arrD[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), false);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
|
|
|
|
//Test 5: Test two linked lists where the first list is a subset of the second - Expected result is FALSE (0)
|
|
int arrE[8] = { 2, 24, -1, 88, 3, 6, 7, 8 };
|
|
for (int i = 0; i < sizeof(arrE) / sizeof(arrE[0]); i++) {
|
|
listB.addToTail(arrE[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), false);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
|
|
|
|
//Test 6: Test two linked lists where the second list is a subset of the first - Expected result is FALSE (0)
|
|
int arrF[4] = { 2, 24, -1, 88 };
|
|
for (int i = 0; i < sizeof(arrF) / sizeof(arrF[0]); i++) {
|
|
listB.addToTail(arrF[i]);
|
|
}
|
|
|
|
testOutput(listA.isEqual(listB.getHeadElement()), false);
|
|
listA.printAll();
|
|
listB.printAll();
|
|
|
|
//Clear listB for new test
|
|
while (!listB.isEmpty()) { listB.deleteFromTail(); }
|
|
} |