/** * \file * \brief PDS HW2 tests * * \author * Christos Choutouridis AEM:8997 * */ #include #include // rand/srand #include // rand/srand #include "distsort.hpp" /* ================================== fullSort ================================== */ /* * */ TEST(TdistCommonUT, fullSort_test1) { std::vector ts_data = {3, 2, 1, 4, 5, 7, 8, 6}; std::vector ts_expected = {1, 2, 3, 4, 5, 6, 7, 8}; bool ts_ascending = true; fullSort(ts_data, ts_ascending); EXPECT_EQ((ts_data == ts_expected), true); } TEST(TdistCommonUT, fullSort_test2) { std::vector ts_data = {3, 2, 1, 4, 5, 7, 8, 6}; std::vector ts_expected = {8, 7, 6, 5, 4, 3, 2, 1}; bool ts_ascending = false; fullSort(ts_data, ts_ascending); EXPECT_EQ((ts_data == ts_expected), true); } /* ================================== elbowSort ================================== */ TEST(TdistCommonUT, elbowSort_test1) { ShadowedVec_t ts_data1(std::vector{3, 2, 1, 4, 5, 5, 7, 8}); ShadowedVec_t ts_data2(std::vector{4, 5, 7, 8, 5, 3, 2, 1}); ShadowedVec_t ts_data3(std::vector{1, 2, 3, 4, 5, 5, 7, 8}); ShadowedVec_t ts_data4(std::vector{8, 7, 5, 5, 4, 3, 2, 1}); std::vector ts_expected = {1, 2, 3, 4, 5, 5, 7, 8}; bool ts_ascending = true; elbowSort(ts_data1, ts_ascending); elbowSort(ts_data2, ts_ascending); elbowSort(ts_data3, ts_ascending); elbowSort(ts_data4, ts_ascending); EXPECT_EQ((ts_data1 == ts_expected), true); EXPECT_EQ((ts_data2 == ts_expected), true); EXPECT_EQ((ts_data3 == ts_expected), true); EXPECT_EQ((ts_data4 == ts_expected), true); } TEST(TdistCommonUT, elbowSort_test2) { ShadowedVec_t ts_data1(std::vector{3, 2, 1, 4, 5, 5, 7, 8}); ShadowedVec_t ts_data2(std::vector{4, 5, 7, 8, 5, 3, 2, 1}); ShadowedVec_t ts_data3(std::vector{1, 2, 3, 4, 5, 5, 7, 8}); ShadowedVec_t ts_data4(std::vector{8, 7, 5, 5, 4, 3, 2, 1}); std::vector ts_expected = {8, 7, 5, 5, 4, 3, 2, 1}; bool ts_ascending = false; elbowSort(ts_data1, ts_ascending); elbowSort(ts_data2, ts_ascending); elbowSort(ts_data3, ts_ascending); elbowSort(ts_data4, ts_ascending); EXPECT_EQ((ts_data1 == ts_expected), true); EXPECT_EQ((ts_data2 == ts_expected), true); EXPECT_EQ((ts_data3 == ts_expected), true); EXPECT_EQ((ts_data4 == ts_expected), true); } TEST(TdistCommonUT, elbowSort_test3) { ShadowedVec_t ts_data(std::vector{8, 7, 5, 5, 4, 3, 2, 1}); std::vector ts_expected_asc = {1, 2, 3, 4, 5, 5, 7, 8}; std::vector ts_expected_des = {8, 7, 5, 5, 4, 3, 2, 1}; // Check alternation for active-shadow vector inside Buffer and elbow algorithm elbowSort(ts_data, true); EXPECT_EQ((ts_data == ts_expected_asc), true); elbowSort(ts_data, false); EXPECT_EQ((ts_data == ts_expected_des), true); elbowSort(ts_data, true); EXPECT_EQ((ts_data == ts_expected_asc), true); elbowSort(ts_data, false); EXPECT_EQ((ts_data == ts_expected_des), true); }