1*c33a039bSNan Zhou #include "utils/stl_utils.hpp"
2*c33a039bSNan Zhou 
3*c33a039bSNan Zhou #include <string>
4*c33a039bSNan Zhou 
5*c33a039bSNan Zhou #include <gmock/gmock.h> // IWYU pragma: keep
6*c33a039bSNan Zhou #include <gtest/gtest.h> // IWYU pragma: keep
7*c33a039bSNan Zhou 
8*c33a039bSNan Zhou // IWYU pragma: no_include <gtest/gtest-message.h>
9*c33a039bSNan Zhou // IWYU pragma: no_include <gtest/gtest-test-part.h>
10*c33a039bSNan Zhou // IWYU pragma: no_include "gtest/gtest_pred_impl.h"
11*c33a039bSNan Zhou 
12*c33a039bSNan Zhou namespace redfish::stl_utils
13*c33a039bSNan Zhou {
14*c33a039bSNan Zhou namespace
15*c33a039bSNan Zhou {
16*c33a039bSNan Zhou using ::testing::ElementsAre;
17*c33a039bSNan Zhou 
18*c33a039bSNan Zhou TEST(FirstDuplicate, ReturnsIteratorToFirstDuplicate)
19*c33a039bSNan Zhou {
20*c33a039bSNan Zhou     std::vector<std::string> strVec = {"s1", "s4", "s1", "s2", "", "s3", "s3"};
21*c33a039bSNan Zhou     auto iter = firstDuplicate(strVec.begin(), strVec.end());
22*c33a039bSNan Zhou     ASSERT_NE(iter, strVec.end());
23*c33a039bSNan Zhou     EXPECT_EQ(*iter, "s3");
24*c33a039bSNan Zhou }
25*c33a039bSNan Zhou 
26*c33a039bSNan Zhou TEST(RemoveDuplicates, AllDuplicatesAreRempvedInplace)
27*c33a039bSNan Zhou {
28*c33a039bSNan Zhou     std::vector<std::string> strVec = {"s1", "s4", "s1", "s2", "", "s3", "s3"};
29*c33a039bSNan Zhou     removeDuplicate(strVec);
30*c33a039bSNan Zhou 
31*c33a039bSNan Zhou     EXPECT_THAT(strVec, ElementsAre("s1", "s4", "s2", "", "s3"));
32*c33a039bSNan Zhou }
33*c33a039bSNan Zhou } // namespace
34*c33a039bSNan Zhou } // namespace redfish::stl_utils
35