/* * Compares 2 movie nodes by a specific method. * Returns: * 1 if the first movie is greater than. * -1 if the first movie is less than. * 0 if they are equal. * 2 if an unknown method was passed. */ int model::InterlacedMovieList::compareMovies(MovieNode* movie1, MovieNode* movie2, const string& method) { if (method.compare(BY_TITLE) == 0) { return compareTitle(*movie1, *movie2); } else if (method.compare(BY_LENGTH) == 0) { return compareLength(*movie1, *movie2); } else { return compareRating(*movie1, *movie2); } return 2; }
int main(void) { printf("\n"); printf("\t --TESTING TREESUPPLEMENT--\n"); printf("\n"); /* Testing createTreeNode */ printf("-- CREATETREENODE\n"); printf("Input to createTreeNode: (\"McDonalds\", \"Fast food\", 3)\n"); void * testNode; testNode = createTreeNode("McDonalds", "Fast food", 3); printf("Output: %p - A pointer address\n", testNode); int x; int correctMembers; correctMembers = 0; char * testName = "McDonalds."; for (x = 0; ((restaurantTNode*)testNode)->name[x] == testName[x]; ++x); if (x == 9) ++correctMembers; else printf("FAILED to copy name\n"); char * testFType = "Fast food."; for (x = 0; ((restaurantTNode*)testNode)->foodType[x] == testFType[x]; ++x); if (x == 9) ++correctMembers; else printf("FAILED to copy foodType\n"); if (((restaurantTNode*)testNode)->rating == 3) ++correctMembers; else printf("FAILED to copy rating\n"); if (correctMembers == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing createTreeNode */ /* Testing compareName */ printf("-- COMPARENAME\n"); int correctNums; correctNums = 0; printf("creating new tree node with createTreeNode(\"Burger King\", \"Fast food\", 4)\n"); void * testNode2; testNode2 = createTreeNode("Burger King", "Fast food", 4); printf("Input to compareName: (%p, %p)\n", testNode, testNode2); printf("{First arguement is the first tree node we created (McDonalds) and second is the new one (Burger King)}\n"); int resultOutput; resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: -1\n"); if (resultOutput == -1) ++correctNums; else printf("FAILED to compare names\n"); printf("Shortening \"Burger King\" to \"Burger Ki\" (equal in length to McDonalds)\n"); ((restaurantTNode*)testNode2)->name[9] = '\0'; printf("Reinputting the original node and the altered node\n"); resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 0\n"); if (resultOutput == 0) ++correctNums; else printf("FAILED to compare names\n"); printf("Shortening \"Burger Ki\" to \"Burger\" (less than the length of McDonalds)\n"); ((restaurantTNode*)testNode2)->name[6] = '\0'; printf("Reinputting the original node and the again altered node\n"); resultOutput = compareName(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 1\n"); if (resultOutput == 1) ++correctNums; else printf("FAILED to compare names\n"); if (correctNums == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing compareName */ /* Testing compareRating */ printf("-- COMPARERATING\n"); correctNums = 0; printf("Input to compareRating: (%p, %p)\n", testNode, testNode2); printf("{First arguement is the first tree node we created, McDonalds (Rating: 3) and second is Burger King (Rating: 4)\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: -1\n"); if (resultOutput == -1) ++correctNums; else printf("FAILED to compare rating\n"); printf("Changing Burger King's rating to 3\n"); ((restaurantTNode*)testNode2)->rating = 3; printf("Reinputting the original node and the altered node\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 0\n"); if (resultOutput == 0) ++correctNums; else printf("FAILED to compare rating\n"); printf("Changing Burger King's rating to 2\n"); ((restaurantTNode*)testNode2)->rating = 2; printf("Reinputting the original node and the altered node\n"); resultOutput = compareRating(testNode, testNode2); printf("Output: %d\n", resultOutput); printf("Expected output: 1\n"); if (resultOutput == 1) ++correctNums; else printf("FAILED to compare rating\n"); if (correctNums == 3) printf("-- SUCCESS\n"); else printf("-- FAIL\n"); printf("\n"); /* End of testing compareRating */ printf("\t --END OF TESTING TREESUPPLEMENT--\n"); printf("\n"); return 0; }