STLUtilsTest.cpp 2.6 KB

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