Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : #include <estd/priority_queue.h> 4 : 5 : #include <gtest/gtest.h> 6 : 7 3 : TEST(PriorityQueueExample, Construction_and_operations) 8 : { 9 : // [EXAMPLE_START] 10 : // construction of a default estd::declare::priority_queue that stores up to 10 elements 11 1 : ::estd::declare::priority_queue<int32_t, 4> q; 12 : 13 : // top() & pop() operations will result in an error as priority_queue is empty 14 : // q.top(); q.pop(); 15 : 16 : // push() elements in priority_queue 17 1 : q.push(20); 18 : 19 : // top() shows the highest priority element on priority_queue 20 1 : ASSERT_EQ(20, q.top()); 21 1 : q.push(4); 22 : 23 : // size() shows the number of elements present in priority_queue 24 1 : ASSERT_EQ(2U, q.size()); 25 : 26 : // max_size() shows the maximum number of elements priority_queue can hold 27 1 : ASSERT_EQ(4U, q.max_size()); 28 1 : q.push(11); 29 1 : ASSERT_EQ(20, q.top()); 30 1 : q.push(5); 31 1 : ASSERT_EQ(4U, q.size()); 32 1 : ASSERT_EQ(4U, q.max_size()); 33 : 34 : // push() operation will throw an error as priority_queue is full 35 : // q.push(12); 36 : 37 1 : q.pop(); 38 1 : ASSERT_EQ(11, q.top()); 39 1 : ASSERT_EQ(3U, q.size()); 40 2 : ASSERT_EQ(4U, q.max_size()); 41 : // [EXAMPLE_END] 42 1 : }