| 8 | #include "fl/stl/cstddef.h" |
| 9 | |
| 10 | FL_TEST_FILE(FL_FILEPATH) { |
| 11 | |
| 12 | using namespace fl; |
| 13 | |
| 14 | // ============================================================================ |
| 15 | // Tests for fl::PriorityQueue (standard max-heap priority queue) |
| 16 | // ============================================================================ |
| 17 | |
| 18 | FL_TEST_CASE("fl::PriorityQueue basic operations") { |
| 19 | FL_SUBCASE("default constructor") { |
| 20 | PriorityQueue<int> pq; |
| 21 | FL_CHECK(pq.empty()); |
| 22 | FL_CHECK_EQ(pq.size(), 0u); |
| 23 | } |
| 24 | |
| 25 | FL_SUBCASE("push and top") { |
| 26 | PriorityQueue<int> pq; |
| 27 | pq.push(5); |
| 28 | FL_CHECK(!pq.empty()); |
| 29 | FL_CHECK_EQ(pq.size(), 1u); |
| 30 | FL_CHECK_EQ(pq.top(), 5); |
| 31 | |
| 32 | pq.push(3); |
| 33 | FL_CHECK_EQ(pq.size(), 2u); |
| 34 | FL_CHECK_EQ(pq.top(), 5); // Max heap by default |
| 35 | |
| 36 | pq.push(7); |
| 37 | FL_CHECK_EQ(pq.size(), 3u); |
| 38 | FL_CHECK_EQ(pq.top(), 7); |
| 39 | } |
| 40 | |
| 41 | FL_SUBCASE("pop operations") { |
| 42 | PriorityQueue<int> pq; |
| 43 | pq.push(5); |
| 44 | pq.push(3); |
| 45 | pq.push(7); |
| 46 | pq.push(1); |
| 47 | pq.push(9); |
| 48 | |
| 49 | FL_CHECK_EQ(pq.top(), 9); |
| 50 | pq.pop(); |
| 51 | FL_CHECK_EQ(pq.top(), 7); |
| 52 | pq.pop(); |
| 53 | FL_CHECK_EQ(pq.top(), 5); |
| 54 | pq.pop(); |
| 55 | FL_CHECK_EQ(pq.top(), 3); |
| 56 | pq.pop(); |
| 57 | FL_CHECK_EQ(pq.top(), 1); |
| 58 | pq.pop(); |
| 59 | FL_CHECK(pq.empty()); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | FL_TEST_CASE("fl::PriorityQueue with custom comparator") { |
| 64 | FL_SUBCASE("min heap with custom comparator") { |
| 65 | // Use custom comparator for min heap (opposite of default) |
| 66 | struct Greater { |
| 67 | bool operator()(int a, int b) const { return a > b; } |
nothing calls this directly
no test coverage detected