|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /**
- * \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 "distbitonic.hpp"
-
-
-
- /* ================================== ascending ================================== */
-
- /*
- * bool ascending<SortMode::Bubbletonic>(size_t node, size_t depth);
- */
- TEST(TdistBubbletonic_UT, ascending_Bubbletonic_test1) {
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(0, 0), true);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(1, 0), false);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(2, 0), true);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(3, 0), false);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(4, 0), true);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(5, 0), false);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(6, 0), true);
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(7, 0), false);
-
- for (size_t node = 0 ; node < 256 ; ++node) {
- EXPECT_EQ(ascending<SortMode::Bubbletonic>(node, 7), ((node % 2) ? false : true) );
- }
- }
-
-
- /* ================================== partner ================================== */
-
- /*
- * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
- * step = 0
- */
- TEST(TdistBubbletonic_UT, partner_Bubbletonic_test1) {
- size_t ts_step = 0;
- size_t ts_expected[] = {1, 0, 3, 2, 5, 4, 7, 6};
-
- for (size_t node = 0 ; node < 8 ; ++node) {
- EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
- }
- }
-
- /*
- * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
- * step = 1
- */
- TEST(TdistBubbletonic_UT, partner_Bubbletonic_test2) {
- size_t ts_step = 1;
- size_t ts_expected[] = {(size_t)-1, 2, 1, 4, 3, 6, 5, 8};
-
- for (size_t node = 0 ; node < 8 ; ++node) {
- EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
- }
- }
-
- /*
- * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
- * various steps
- */
- TEST(TdistBubbletonic_UT, partner_Bubbletonic_test3) {
-
- size_t ts_even_expected[] = {
- 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
- };
- size_t ts_odd_expected[] = {
- (size_t)-1, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16
- };
-
- for (size_t step = 0 ; step < 32 ; ++step) {
- if (step % 2) {
- for (size_t node = 0; node < 16; ++node) {
- EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_odd_expected[node]);
- }
- }
- else {
- for (size_t node = 0; node < 16; ++node) {
- EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_even_expected[node]);
- }
- }
- }
- }
-
-
- /* ================================== keepsmall ================================== */
- /*
- * bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, size_t depth);
- * Assertion check
- */
- TEST(TdistBubbletonic_UT, keepsmall_test1) {
- ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(0, 0, 0), "");
- ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(1, 1, 42), "");
- ASSERT_DEATH(keepsmall<SortMode::Bubbletonic>(7, 7, 42), "");
- }
-
- /*
- * bool keepsmall<SortMode::Bubbletonic>(size_t node, size_t partner, size_t depth);
- */
- TEST(TdistBubbletonic_UT, keepsmall_test2) {
- // Check various combinations
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 1, 42), true);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 3, 42), true);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(2, 1, 42), false);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 1, 42), false);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(0, 1, 42), true);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 32,42), true);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(7, 1, 42), false);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(4, 0, 42), false);
- EXPECT_EQ(keepsmall<SortMode::Bubbletonic>(4, 9, 42), true);
- }
-
-
-
- TEST(TdistBubbletonic_UT, distbubbletonic_test1) {
- AllData_t ts_Data {
- Data_t (8), Data_t (8)
- };
-
- std::srand(unsigned(std::time(nullptr)));
- for (auto& v : ts_Data) {
- std::generate(v.begin(), v.end(), std::rand);
- }
-
- distbubbletonic(2, ts_Data);
-
- auto max = std::numeric_limits<Data_t::value_type>::min();
- for (auto& v : ts_Data) {
- EXPECT_EQ((max <= v[0]), true);
- EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
- max = v.back();
- }
- }
-
-
- TEST(TdistBubbletonic_UT, distbubbletonic_test2) {
- AllData_t ts_Data {
- Data_t (8), Data_t (8), Data_t (8), Data_t (8)
- };
-
- std::srand(unsigned(std::time(nullptr)));
- for (auto& v : ts_Data) {
- std::generate(v.begin(), v.end(), std::rand);
- }
-
- distbubbletonic(4, ts_Data);
-
- auto max = std::numeric_limits<Data_t::value_type>::min();
- for (auto& v : ts_Data) {
- EXPECT_EQ((max <= v[0]), true);
- EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
- max = v.back();
- }
- }
-
- TEST(TdistBubbletonic_UT, distbubbletonic_test3) {
- AllData_t ts_Data {
- Data_t (32), Data_t (32), Data_t (32), Data_t (32),
- Data_t (32), Data_t (32), Data_t (32), Data_t (32)
- };
-
- std::srand(unsigned(std::time(nullptr)));
- for (auto& v : ts_Data) {
- std::generate(v.begin(), v.end(), std::rand);
- }
-
- distbubbletonic(8, ts_Data);
-
- auto max = std::numeric_limits<Data_t::value_type>::min();
- for (auto& v : ts_Data) {
- EXPECT_EQ((max <= v[0]), true);
- EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
- max = v.back();
- }
- }
|