AUTH's THMMY "Parallel and distributed systems" course assignments.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

94 linhas
3.2 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. /* ================================== fullSort ================================== */
  14. /*
  15. *
  16. */
  17. TEST(TdistCommonUT, fullSort_test1) {
  18. std::vector<uint8_t> ts_data = {3, 2, 1, 4, 5, 7, 8, 6};
  19. std::vector<uint8_t> ts_expected = {1, 2, 3, 4, 5, 6, 7, 8};
  20. bool ts_ascending = true;
  21. fullSort(ts_data, ts_ascending);
  22. EXPECT_EQ((ts_data == ts_expected), true);
  23. }
  24. TEST(TdistCommonUT, fullSort_test2) {
  25. std::vector<uint8_t> ts_data = {3, 2, 1, 4, 5, 7, 8, 6};
  26. std::vector<uint8_t> ts_expected = {8, 7, 6, 5, 4, 3, 2, 1};
  27. bool ts_ascending = false;
  28. fullSort(ts_data, ts_ascending);
  29. EXPECT_EQ((ts_data == ts_expected), true);
  30. }
  31. /* ================================== elbowSort ================================== */
  32. TEST(TdistCommonUT, elbowSort_test1) {
  33. ShadowedVec_t<uint8_t> ts_data1(std::vector<uint8_t>{3, 2, 1, 4, 5, 5, 7, 8});
  34. ShadowedVec_t<uint8_t> ts_data2(std::vector<uint8_t>{4, 5, 7, 8, 5, 3, 2, 1});
  35. ShadowedVec_t<uint8_t> ts_data3(std::vector<uint8_t>{1, 2, 3, 4, 5, 5, 7, 8});
  36. ShadowedVec_t<uint8_t> ts_data4(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
  37. std::vector<uint8_t> ts_expected = {1, 2, 3, 4, 5, 5, 7, 8};
  38. bool ts_ascending = true;
  39. elbowSort(ts_data1, ts_ascending);
  40. elbowSort(ts_data2, ts_ascending);
  41. elbowSort(ts_data3, ts_ascending);
  42. elbowSort(ts_data4, ts_ascending);
  43. EXPECT_EQ((ts_data1 == ts_expected), true);
  44. EXPECT_EQ((ts_data2 == ts_expected), true);
  45. EXPECT_EQ((ts_data3 == ts_expected), true);
  46. EXPECT_EQ((ts_data4 == ts_expected), true);
  47. }
  48. TEST(TdistCommonUT, elbowSort_test2) {
  49. ShadowedVec_t<uint8_t> ts_data1(std::vector<uint8_t>{3, 2, 1, 4, 5, 5, 7, 8});
  50. ShadowedVec_t<uint8_t> ts_data2(std::vector<uint8_t>{4, 5, 7, 8, 5, 3, 2, 1});
  51. ShadowedVec_t<uint8_t> ts_data3(std::vector<uint8_t>{1, 2, 3, 4, 5, 5, 7, 8});
  52. ShadowedVec_t<uint8_t> ts_data4(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
  53. std::vector<uint8_t> ts_expected = {8, 7, 5, 5, 4, 3, 2, 1};
  54. bool ts_ascending = false;
  55. elbowSort(ts_data1, ts_ascending);
  56. elbowSort(ts_data2, ts_ascending);
  57. elbowSort(ts_data3, ts_ascending);
  58. elbowSort(ts_data4, ts_ascending);
  59. EXPECT_EQ((ts_data1 == ts_expected), true);
  60. EXPECT_EQ((ts_data2 == ts_expected), true);
  61. EXPECT_EQ((ts_data3 == ts_expected), true);
  62. EXPECT_EQ((ts_data4 == ts_expected), true);
  63. }
  64. TEST(TdistCommonUT, elbowSort_test3) {
  65. ShadowedVec_t<uint8_t> ts_data(std::vector<uint8_t>{8, 7, 5, 5, 4, 3, 2, 1});
  66. std::vector<uint8_t> ts_expected_asc = {1, 2, 3, 4, 5, 5, 7, 8};
  67. std::vector<uint8_t> ts_expected_des = {8, 7, 5, 5, 4, 3, 2, 1};
  68. // Check alternation for active-shadow vector inside Buffer and elbow algorithm
  69. elbowSort(ts_data, true);
  70. EXPECT_EQ((ts_data == ts_expected_asc), true);
  71. elbowSort(ts_data, false);
  72. EXPECT_EQ((ts_data == ts_expected_des), true);
  73. elbowSort(ts_data, true);
  74. EXPECT_EQ((ts_data == ts_expected_asc), true);
  75. elbowSort(ts_data, false);
  76. EXPECT_EQ((ts_data == ts_expected_des), true);
  77. }