STLUtilsTest.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-17
  6. * Changed: 2020-10-29
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. #include <vector>
  12. #include <list>
  13. #include <string>
  14. namespace {
  15. class STLUtilsTest : public ::testing::Test {
  16. protected:
  17. STLUtilsTest() = default;
  18. ~STLUtilsTest() override = default;
  19. void SetUp() override {}
  20. void TearDown() override {}
  21. };
  22. TEST_F(STLUtilsTest, contains)
  23. {
  24. std::vector<int> values {1, 13, 7, 8};
  25. std::list<std::string> names {"Tim", "Alex", "Nadine"};
  26. ASSERT_TRUE((ls_std::STLUtils::contains(values, 1)));
  27. ASSERT_TRUE((ls_std::STLUtils::contains(values, 13)));
  28. ASSERT_TRUE((ls_std::STLUtils::contains(values, 7)));
  29. ASSERT_TRUE((ls_std::STLUtils::contains(values, 8)));
  30. ASSERT_TRUE((ls_std::STLUtils::contains(names, "Tim")));
  31. ASSERT_TRUE((ls_std::STLUtils::contains(names, "Alex")));
  32. ASSERT_TRUE((ls_std::STLUtils::contains(names, "Nadine")));
  33. }
  34. TEST_F(STLUtilsTest, containsNegative)
  35. {
  36. std::vector<int> values{1, 13, 7, 8};
  37. std::list<std::string> names{"Tim", "Alex", "Nadine"};
  38. ASSERT_FALSE((ls_std::STLUtils::contains(values, 55)));
  39. ASSERT_FALSE((ls_std::STLUtils::contains(values, 9)));
  40. ASSERT_FALSE((ls_std::STLUtils::contains(names, "Lena")));
  41. ASSERT_FALSE((ls_std::STLUtils::contains(names, "Mirco")));
  42. }
  43. TEST_F(STLUtilsTest, getListElementAt)
  44. {
  45. std::list<int> values{1, 13, 7, 8};
  46. std::list<std::string> names{"Tim", "Alex", "Nadine"};
  47. ASSERT_EQ(1, (ls_std::STLUtils::getListElementAt(values, 0)));
  48. ASSERT_EQ(13, (ls_std::STLUtils::getListElementAt(values, 1)));
  49. ASSERT_EQ(7, (ls_std::STLUtils::getListElementAt(values, 2)));
  50. ASSERT_EQ(8, (ls_std::STLUtils::getListElementAt(values, 3)));
  51. ASSERT_STREQ("Tim", ls_std::STLUtils::getListElementAt(names, 0).c_str());
  52. ASSERT_STREQ("Alex", ls_std::STLUtils::getListElementAt(names, 1).c_str());
  53. ASSERT_STREQ("Nadine", ls_std::STLUtils::getListElementAt(names, 2).c_str());
  54. }
  55. TEST_F(STLUtilsTest, getListElementAtNegative)
  56. {
  57. std::list<int> values{1, 13, 7, 8};
  58. std::list<std::string> names{"Tim", "Alex", "Nadine"};
  59. ASSERT_EQ(0, (ls_std::STLUtils::getListElementAt(values, 15)));
  60. ASSERT_STREQ("", ls_std::STLUtils::getListElementAt(names, 15).c_str());
  61. }
  62. }