AUTH's THMMY "Parallel and distributed systems" course assignments.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

185 lignes
5.5 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 "distbitonic.hpp"
  13. /* ================================== ascending ================================== */
  14. /*
  15. * bool ascending<SortMode::Bubbletonic>(size_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 (size_t node = 0 ; node < 256 ; ++node) {
  27. EXPECT_EQ(ascending<SortMode::Bubbletonic>(node, 7), ((node % 2) ? false : true) );
  28. }
  29. }
  30. /* ================================== partner ================================== */
  31. /*
  32. * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
  33. * step = 0
  34. */
  35. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test1) {
  36. size_t ts_step = 0;
  37. size_t ts_expected[] = {1, 0, 3, 2, 5, 4, 7, 6};
  38. for (size_t node = 0 ; node < 8 ; ++node) {
  39. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
  40. }
  41. }
  42. /*
  43. * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
  44. * step = 1
  45. */
  46. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test2) {
  47. size_t ts_step = 1;
  48. size_t ts_expected[] = {(size_t)-1, 2, 1, 4, 3, 6, 5, 8};
  49. for (size_t node = 0 ; node < 8 ; ++node) {
  50. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, ts_step), ts_expected[node]);
  51. }
  52. }
  53. /*
  54. * size_t partner<SortMode::Bubbletonic>(size_t node, size_t step);
  55. * various steps
  56. */
  57. TEST(TdistBubbletonic_UT, partner_Bubbletonic_test3) {
  58. size_t ts_even_expected[] = {
  59. 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
  60. };
  61. size_t ts_odd_expected[] = {
  62. (size_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 (size_t node = 0; node < 16; ++node) {
  67. EXPECT_EQ(partner<SortMode::Bubbletonic>(node, step), ts_odd_expected[node]);
  68. }
  69. }
  70. else {
  71. for (size_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>(size_t node, size_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>(size_t node, size_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. TEST(TdistBubbletonic_UT, distbubbletonic_test1) {
  103. AllData_t ts_Data {
  104. Data_t (8), Data_t (8)
  105. };
  106. std::srand(unsigned(std::time(nullptr)));
  107. for (auto& v : ts_Data) {
  108. std::generate(v.begin(), v.end(), std::rand);
  109. }
  110. distbubbletonic(2, ts_Data);
  111. auto max = std::numeric_limits<Data_t::value_type>::min();
  112. for (auto& v : ts_Data) {
  113. EXPECT_EQ((max <= v[0]), true);
  114. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  115. max = v.back();
  116. }
  117. }
  118. TEST(TdistBubbletonic_UT, distbubbletonic_test2) {
  119. AllData_t ts_Data {
  120. Data_t (8), Data_t (8), Data_t (8), Data_t (8)
  121. };
  122. std::srand(unsigned(std::time(nullptr)));
  123. for (auto& v : ts_Data) {
  124. std::generate(v.begin(), v.end(), std::rand);
  125. }
  126. distbubbletonic(4, ts_Data);
  127. auto max = std::numeric_limits<Data_t::value_type>::min();
  128. for (auto& v : ts_Data) {
  129. EXPECT_EQ((max <= v[0]), true);
  130. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  131. max = v.back();
  132. }
  133. }
  134. TEST(TdistBubbletonic_UT, distbubbletonic_test3) {
  135. AllData_t ts_Data {
  136. Data_t (32), Data_t (32), Data_t (32), Data_t (32),
  137. Data_t (32), Data_t (32), Data_t (32), Data_t (32)
  138. };
  139. std::srand(unsigned(std::time(nullptr)));
  140. for (auto& v : ts_Data) {
  141. std::generate(v.begin(), v.end(), std::rand);
  142. }
  143. distbubbletonic(8, ts_Data);
  144. auto max = std::numeric_limits<Data_t::value_type>::min();
  145. for (auto& v : ts_Data) {
  146. EXPECT_EQ((max <= v[0]), true);
  147. EXPECT_EQ(std::is_sorted(v.begin(), v.end()), true);
  148. max = v.back();
  149. }
  150. }