|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /**
- * \file
- * \brief PDS HW2 tests
- *
- * \author
- * Christos Choutouridis AEM:8997
- * <cchoutou@ece.auth.gr>
- */
-
- #include <gtest/gtest.h>
-
- #include <algorithm> // rand/srand
- #include <ctime> // rand/srand
- #include "distsort.hpp"
-
-
- /* ================================== fullSort ================================== */
-
- /*
- *
- */
- TEST(TdistCommonUT, fullSort_test1) {
- std::vector<uint8_t> ts_data = {3, 2, 1, 4, 5, 7, 8, 6};
- std::vector<uint8_t> 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<uint8_t> ts_data = {3, 2, 1, 4, 5, 7, 8, 6};
- std::vector<uint8_t> 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<uint8_t> ts_data1(std::vector<uint8_t>{3, 2, 1, 4, 5, 5, 7, 8});
- ShadowedVec_t<uint8_t> ts_data2(std::vector<uint8_t>{4, 5, 7, 8, 5, 3, 2, 1});
- ShadowedVec_t<uint8_t> ts_data3(std::vector<uint8_t>{1, 2, 3, 4, 5, 5, 7, 8});
- ShadowedVec_t<uint8_t> ts_data4(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
- std::vector<uint8_t> 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<uint8_t> ts_data1(std::vector<uint8_t>{3, 2, 1, 4, 5, 5, 7, 8});
- ShadowedVec_t<uint8_t> ts_data2(std::vector<uint8_t>{4, 5, 7, 8, 5, 3, 2, 1});
- ShadowedVec_t<uint8_t> ts_data3(std::vector<uint8_t>{1, 2, 3, 4, 5, 5, 7, 8});
- ShadowedVec_t<uint8_t> ts_data4(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
- std::vector<uint8_t> 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<uint8_t> ts_data(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
- std::vector<uint8_t> ts_expected_asc = {1, 2, 3, 4, 5, 5, 7, 8};
- std::vector<uint8_t> 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);
- }
-
|