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.

tests_BubbletonicUtils.cpp 4.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * Throw check (Not assert - ASSERT_DEATH)
  81. */
  82. TEST(TdistBubbletonic_UT, keepsmall_test1) {
  83. // node and partner must differ or else ...
  84. EXPECT_THROW(keepSmall<SortMode::Bubbletonic>(0, 0, 0), std::runtime_error);
  85. EXPECT_THROW(keepSmall<SortMode::Bubbletonic>(1, 1, 42), std::runtime_error);
  86. EXPECT_THROW(keepSmall<SortMode::Bubbletonic>(7, 7, 42), std::runtime_error);
  87. }
  88. /*
  89. * bool keepSmall<SortMode::Bubbletonic>(mpi_id_t node, mpi_id_t partner, size_t depth);
  90. */
  91. TEST(TdistBubbletonic_UT, keepsmall_test2) {
  92. // Check various combinations
  93. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
  94. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 3, 42), true);
  95. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(2, 1, 42), false);
  96. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
  97. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(0, 1, 42), true);
  98. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 32, 42), true);
  99. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(7, 1, 42), false);
  100. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 0, 42), false);
  101. EXPECT_EQ(keepSmall<SortMode::Bubbletonic>(4, 9, 42), true);
  102. }
  103. /* ================================== isActive ================================== */
  104. /*
  105. * bool isActive(mpi_id_t node, size_t nodes);
  106. * Throw check
  107. */
  108. TEST(TdistBubbletonic_UT, isActive_test1) {
  109. EXPECT_THROW(isActive(0, 0), std::runtime_error);
  110. EXPECT_THROW(isActive(0, static_cast<size_t>(std::numeric_limits<mpi_id_t>::max()) + 1), std::runtime_error);
  111. }
  112. /*
  113. * bool isActive(mpi_id_t node, size_t nodes);
  114. * Boundary 3 BVA
  115. */
  116. TEST(TdistBubbletonic_UT, isActive_test2) {
  117. EXPECT_EQ(isActive(-1, 8), false);
  118. EXPECT_EQ(isActive(0, 8), true);
  119. EXPECT_EQ(isActive(1, 8), true);
  120. EXPECT_EQ(isActive(7, 8), true);
  121. EXPECT_EQ(isActive(8, 8), false);
  122. EXPECT_EQ(isActive(9, 8), false);
  123. }