AUTH's THMMY "Parallel and distributed systems" course assignments.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

185 wiersze
5.7 KiB

  1. /**
  2. * \file
  3. * \brief PDS HW2 tests
  4. *
  5. * \author
  6. * Christos Choutouridis AEM:8997
  7. * <cchoutou@ece.auth.gr>
  8. */
  9. #include <gtest/gtest.h>
  10. #include <algorithm> // rand/srand
  11. #include <ctime> // rand/srand
  12. #include "distsort.hpp"
  13. /* ================================== ascending ================================== */
  14. /*
  15. * bool ascending<SortMode::Bubbletonic>(mpi_id_t node, size_t depth);
  16. */
  17. TEST(TdistBubbletonic_UT, ascending_Bubbletonic_test1) {
  18. EXPECT_EQ(ascending<SortMode::Bubbletonic>(0, 0), true);
  19. EXPECT_EQ(ascending<SortMode::Bubbletonic>(1, 0), false);
  20. EXPECT_EQ(ascending<SortMode::Bubbletonic>(2, 0), true);
  21. EXPECT_EQ(ascending<SortMode::Bubbletonic>(3, 0), false);
  22. EXPECT_EQ(ascending<SortMode::Bubbletonic>(4, 0), true);
  23. EXPECT_EQ(ascending<SortMode::Bubbletonic>(5, 0), false);
  24. EXPECT_EQ(ascending<SortMode::Bubbletonic>(6, 0), true);
  25. EXPECT_EQ(ascending<SortMode::Bubbletonic>(7, 0), false);
  26. for (mpi_id_t node = 0 ; node < 256 ; ++node) {
  27. EXPECT_EQ(ascending<SortMode::Bubbletonic>(node, 7), ((node % 2) ? false : true) );
  28. }
  29. }
  30. /* ================================== partner ================================== */
  31. /*
  32. * mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
  33. * step = 0
  34. */
  35. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test1) {
  36. size_t ts_step = 0;
  37. mpi_id_t ts_expected[] = {1, 0, 3, 2, 5, 4, 7, 6};
  38. for (mpi_id_t node = 0 ; node < 8 ; ++node) {
  39. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
  40. }
  41. }
  42. /*
  43. * mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
  44. * step = 1
  45. */
  46. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test2) {
  47. size_t ts_step = 1;
  48. mpi_id_t ts_expected[] = {(mpi_id_t)-1, 2, 1, 4, 3, 6, 5, 8};
  49. for (mpi_id_t node = 0 ; node < 8 ; ++node) {
  50. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
  51. }
  52. }
  53. /*
  54. * mpi_id_t partner<SortMode::Bubbletonic>(mpi_id_t node, size_t step);
  55. * various steps
  56. */
  57. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test3) {
  58. mpi_id_t ts_even_expected[] = {
  59. 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
  60. };
  61. mpi_id_t ts_odd_expected[] = {
  62. (mpi_id_t)-1, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16
  63. };
  64. for (size_t step = 0 ; step < 32 ; ++step) {
  65. if (step % 2) {
  66. for (mpi_id_t node = 0; node < 16; ++node) {
  67. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_odd_expected[node]);
  68. }
  69. }
  70. else {
  71. for (mpi_id_t node = 0; node < 16; ++node) {
  72. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_even_expected[node]);
  73. }
  74. }
  75. }
  76. }
  77. /* ================================== keepSmall ================================== */
  78. /*
  79. * bool keepSmall<SortMode::Bubbletonic>(mpi_id_t node, mpi_id_t partner, size_t depth);
  80. * Assertion check
  81. */
  82. TEST(TdistBubbletonic_UT, keepsmall_test1) {
  83. ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(0, 0, 0), "");
  84. ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(1, 1, 42), "");
  85. ASSERT_DEATH(keepSmall<SortMode::Bubbletonic>(7, 7, 42), "");
  86. }
  87. /*
  88. * bool keepSmall<SortMode::Bubbletonic>(mpi_id_t node, mpi_id_t partner, size_t depth);
  89. */
  90. TEST(TdistBubbletonic_UT, keepsmall_test2) {
  91. // Check various combinations
  92. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
  93. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 3, 42), true);
  94. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(2, 1, 42), false);
  95. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
  96. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
  97. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 32, 42), true);
  98. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
  99. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 0, 42), false);
  100. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 9, 42), true);
  101. }
  102. #if 0
  103. TEST(TdistBubbletonic_UT, distBubbletonic_test1) {
  104. AllData_t ts_Data {
  105. ShadowedVec_t (8), ShadowedVec_t (8)
  106. };
  107. std::srand(unsigned(std::time(nullptr)));
  108. for (auto& v : ts_Data) {
  109. std::generate(v.begin(), v.end(), std::rand);
  110. }
  111. distBubbletonic(2, ts_Data);
  112. auto max = std::numeric_limits<ShadowedVec_t::value_type>::min();
  113. for (auto& v : ts_Data) {
  114. EXPECT_EQ((max <= v[0]), true);
  115. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  116. max = v.back();
  117. }
  118. }
  119. TEST(TdistBubbletonic_UT, distBubbletonic_test2) {
  120. AllData_t ts_Data {
  121. ShadowedVec_t (8), ShadowedVec_t (8), ShadowedVec_t (8), ShadowedVec_t (8)
  122. };
  123. std::srand(unsigned(std::time(nullptr)));
  124. for (auto& v : ts_Data) {
  125. std::generate(v.begin(), v.end(), std::rand);
  126. }
  127. distBubbletonic(4, ts_Data);
  128. auto max = std::numeric_limits<ShadowedVec_t::value_type>::min();
  129. for (auto& v : ts_Data) {
  130. EXPECT_EQ((max <= v[0]), true);
  131. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  132. max = v.back();
  133. }
  134. }
  135. TEST(TdistBubbletonic_UT, distBubbletonic_test3) {
  136. AllData_t ts_Data {
  137. ShadowedVec_t (32), ShadowedVec_t (32), ShadowedVec_t (32), ShadowedVec_t (32),
  138. ShadowedVec_t (32), ShadowedVec_t (32), ShadowedVec_t (32), ShadowedVec_t (32)
  139. };
  140. std::srand(unsigned(std::time(nullptr)));
  141. for (auto& v : ts_Data) {
  142. std::generate(v.begin(), v.end(), std::rand);
  143. }
  144. distBubbletonic(8, ts_Data);
  145. auto max = std::numeric_limits<ShadowedVec_t::value_type>::min();
  146. for (auto& v : ts_Data) {
  147. EXPECT_EQ((max <= v[0]), true);
  148. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  149. max = v.back();
  150. }
  151. }
  152. #endif