Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : #include "estd/ordered_vector.h" 4 : 5 : #include <gmock/gmock.h> 6 : 7 : namespace 8 : { 9 1 : void example_construction() 10 : { 11 : // [EXAMPLE_ORDERED_VECTOR_START] 12 1 : using IntVector10 = ::estd::declare::ordered_vector<int32_t, 10, std::less<int32_t>>; 13 : // declare the ordered vector of size 10 14 1 : ::estd::declare::ordered_vector<int32_t, 10> a; 15 : // inserting elements to the ordered vector created 16 1 : a.insert(3); 17 1 : EXPECT_THAT(a, testing::ElementsAre(3)); 18 1 : a.insert(2); 19 1 : EXPECT_THAT(a, testing::ElementsAre(2, 3)); 20 1 : a.insert(1); 21 : // ordered elements in the vector 22 1 : EXPECT_THAT(a, testing::ElementsAre(1, 2, 3)); 23 1 : a.resize(2); 24 : // element size reduced to 2 25 1 : EXPECT_THAT(a, testing::ElementsAre(1, 2)); 26 : // makes the vector empty 27 1 : a.clear(); 28 1 : a.find_or_insert(5); 29 : // Since element 5 is not found, it is inserted otherwise returns position. 30 1 : EXPECT_THAT(a, testing::ElementsAre(5)); 31 : // Check whether the value is in the vector 32 1 : ASSERT_TRUE(a.contains(5)); 33 : // finds and remove particular element 34 : // a.remove_if(comp); removes element based on predicate 35 1 : a.remove(5); 36 1 : a.insert(1); 37 : // erase element using iterator 38 1 : a.erase(a.begin()); 39 1 : a.insert(1); 40 1 : a.insert(2); 41 : // erase element using range of iterators 42 1 : a.erase(a.begin(), a.end()); 43 1 : a.insert(5); 44 1 : IntVector10::const_iterator itr = a.begin(); 45 1 : itr++; 46 : // returns the position of the value mentioned 47 2 : ASSERT_EQ(*itr, 2); 48 : // [EXAMPLE_ORDERED_VECTOR_END] 49 1 : } 50 : } // namespace 51 : 52 3 : TEST(OrderedVectorExample, run_examples) { example_construction(); }