// test_class_SSArray_equality_comparisons // Test suite for class template SSArray, comparisons ==, != // Pre: None. // Post: // Pass/fail status of tests have been registered with t. // Appropriate messages have been printed to cout. // Does not throw (No-Throw Guarantee) void test_class_SSArray_equality_comparisons(Tester & t) { std::cout << "Test Suite: class template SSArray - " << "equality comparisons" << std::endl; bool correctType; // result of type checking const int theSize = 10; int i; // Counter SSArray<int> tai1(theSize); for (i = 0; i < theSize; ++i) tai1[i] = 15 - i * i; const SSArray<int> & tai1Ref = tai1; SSArray<int> tai1Copy(tai1Ref); SSArray<int> tai2(theSize-1); for (i = 0; i < theSize-1; ++i) tai2[i] = 15 - i * i; const SSArray<int> & tai2Ref = tai2; // operator== return type correctType = TypeCheck<bool>::check(tai1 == tai1Copy); t.test(correctType, "operator==, return type"); // operator!= return type correctType = TypeCheck<bool>::check(tai1 != tai1Copy); t.test(correctType, "operator!=, return type"); // Check equality of copies t.test(tai1 == tai1Copy, "Equality of copies"); // Check inequality of copies t.test(!(tai1 != tai1Copy), "Inequality of copies"); // Check equality of different sizes #1 // (compilation checks constness of op==) t.test(!(tai1Ref == tai2Ref), "Equality of different sizes #1"); // Check inequality of different sizes #1 // (compilation checks constness of op!=) t.test(tai1Ref != tai2Ref, "Inequality of different sizes #1"); // Check equality of different sizes #2 t.test(!(tai2Ref == tai1Ref), "Equality of different sizes #2"); // Check inequality of different sizes #2 t.test(tai2Ref != tai1Ref, "Inequality of different sizes #2"); // Modify copy ++tai1Copy[theSize-1]; // Check equality of modification of copy t.test(!(tai1 == tai1Copy), "Equality of modification of copy"); // Check inequality of modification of copy t.test(tai1 != tai1Copy, "Inequality of modification of copy"); }
// test_class_KSArray_order_comparisons // Test suite for class KSArray, comparisons <, <=, >, >= // Pre: None. // Post: // Pass/fail status of tests have been registered with t. // Appropriate messages have been printed to cout. // Does not throw (No-Throw Guarantee) void test_class_KSArray_order_comparisons(Tester & t) { std::cout << "Test Suite: class KSArray - comparisons" << std::endl; bool correctType; // result of type checking const int theSize = 10; int i; // Counter KSArray<int> tai1(theSize); for (i = 0; i < theSize; ++i) tai1[i] = 15 - i * i; const KSArray<int> tai1Eq(tai1); // Equal to tai1 KSArray<int> tai1Sm1(tai1); // Smaller than tai1, due to values --tai1Sm1[5]; KSArray<int> tai1Sm2(theSize-2); // Smaller than tai1, due to size for (i = 0; i < tai1Sm2.size(); ++i) tai1Sm2[i] = tai1[i]; KSArray<int> cmh(theSize+1); for (i = 0; i < theSize; ++i) cmh[i] = 15 - i * i; cmh[theSize-1]--; // operator< return type correctType = TypeCheck<bool>::check(tai1 < tai1Eq); t.test(correctType, "operator<, return type"); // operator<= return type correctType = TypeCheck<bool>::check(tai1 <= tai1Eq); t.test(correctType, "operator<=, return type"); // operator> return type correctType = TypeCheck<bool>::check(tai1 > tai1Eq); t.test(correctType, "operator>, return type"); // operator>= return type correctType = TypeCheck<bool>::check(tai1 >= tai1Eq); t.test(correctType, "operator>=, return type"); // Equal arrays, operator< t.test(!(tai1 < tai1Eq), "Equal arrays, operator<"); // Equal arrays, operator<= t.test(tai1 <= tai1Eq, "Equal arrays, operator<="); // Equal arrays, operator> t.test(!(tai1 > tai1Eq), "Equal arrays, operator>"); // Equal arrays, operator>= t.test(tai1 >= tai1Eq, "Equal arrays, operator>="); // Differing values #1, operator< t.test(!(tai1 < tai1Sm1), "Differing values #1, operator<"); t.test(!(tai1<cmh),"! 223<222"); // Differing values #1, operator<= t.test(!(tai1 <= tai1Sm1), "Differing values #1, operator<="); // Differing values #1, operator> t.test(tai1 > tai1Sm1, "Differing values #1, operator>"); // Differing values #1, operator>= t.test(tai1 >= tai1Sm1, "Differing values #1, operator>="); // Differing values #2, operator< t.test(tai1Sm1 < tai1, "Differing values #2, operator<"); // Differing values #2, operator<= t.test(tai1Sm1 <= tai1, "Differing values #2, operator<="); // Differing values #2, operator> t.test(!(tai1Sm1 > tai1), "Differing values #2, operator>"); // Differing values #2, operator>= t.test(!(tai1Sm1 >= tai1), "Differing values #2, operator>="); // Differing sizes #1, operator< t.test(!(tai1 < tai1Sm2), "Differing sizes #1, operator<"); // Differing sizes #1, operator<= t.test(!(tai1 <= tai1Sm2), "Differing sizes #1, operator<="); // Differing sizes #1, operator> t.test(tai1 > tai1Sm2, "Differing sizes #1, operator>"); // Differing sizes #1, operator>= t.test(tai1 >= tai1Sm2, "Differing sizes #1, operator>="); // Differing sizes #2, operator< t.test(tai1Sm2 < tai1, "Differing sizes #2, operator<"); // Differing sizes #2, operator<= t.test(tai1Sm2 <= tai1, "Differing sizes #2, operator<="); // Differing sizes #2, operator> t.test(!(tai1Sm2 > tai1), "Differing sizes #2, operator>"); // Differing sizes #2, operator>= t.test(!(tai1Sm2 >= tai1), "Differing sizes #2, operator>="); }