MCPcopy Create free account
hub / github.com/FastLED/FastLED / test_container_shrink_to_fit

Function test_container_shrink_to_fit

tests/test_container_helpers.h:685–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

683// Test shrink_to_fit for heap-based containers
684template<typename Container>
685void test_container_shrink_to_fit() {
686 Container c;
687
688 // Add many elements
689 for (int i = 0; i < 50; ++i) {
690 populate(c, make_shared_int(i));
691 }
692 // Test capacity() - COMPILER ERROR if capacity() doesn't exist
693 auto large_capacity = c.capacity();
694 FL_CHECK(large_capacity > 50);
695
696 // Remove most elements
697 for (int i = 0; i < 40; ++i) {
698 c.pop_back();
699 }
700 FL_CHECK(c.capacity() >= large_capacity); // Capacity not reduced yet
701
702 // Shrink - COMPILER ERROR if shrink_to_fit() doesn't exist
703 c.shrink_to_fit();
704 FL_CHECK(c.capacity() <= large_capacity); // Should be reduced
705 FL_CHECK(c.size() == 10); // Size preserved
706}
707
708// Test max_size
709template<typename Container>

Callers

nothing calls this directly

Calls 6

populateFunction · 0.85
make_shared_intFunction · 0.85
capacityMethod · 0.45
pop_backMethod · 0.45
shrink_to_fitMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected