STLUtilsTest.cpp 2.3 KB

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