Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2021-07-09 14:58:54 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-07-09 14:58:54 +0300
commitd8a0b111574275ee7b156a07dd3d0fefdbf61f53 (patch)
tree5e1fec77cc42cab89a0f8ebde6304df55c1b8dc7 /tests/libslic3r
parent5bbe76003e1031d4dce6000ae2812e745e4fe0e0 (diff)
GCC does not consider std::pair<std::pair<...>, ...> to be trivially
copiable, thus fixing the unit tests with a custom trivially copyable type.
Diffstat (limited to 'tests/libslic3r')
-rw-r--r--tests/libslic3r/test_mutable_priority_queue.cpp161
1 files changed, 83 insertions, 78 deletions
diff --git a/tests/libslic3r/test_mutable_priority_queue.cpp b/tests/libslic3r/test_mutable_priority_queue.cpp
index 83ac28793..2b446b9c4 100644
--- a/tests/libslic3r/test_mutable_priority_queue.cpp
+++ b/tests/libslic3r/test_mutable_priority_queue.cpp
@@ -131,142 +131,147 @@ TEST_CASE("Mutable priority queue - basic tests", "[MutableSkipHeapPriorityQueue
}
TEST_CASE("Mutable priority queue - reshedule first", "[MutableSkipHeapPriorityQueue]") {
+ struct MyValue {
+ int value;
+ int *ptr;
+ size_t idx;
+ };
SECTION("reschedule top with highest prio leaves order unchanged") {
- auto q = make_miniheap_mutable_priority_queue<std::pair<std::pair<int, int*>, size_t>, 4, false>(
- [](std::pair<std::pair<int, int*>, size_t>& v, size_t idx) { v.second = idx; },
- [](std::pair<std::pair<int, int*>, size_t>& l, std::pair<std::pair<int, int*>, size_t>& r) { return l.first.first < r.first.first; });
+ auto q = make_miniheap_mutable_priority_queue<MyValue, 4, false>(
+ [](MyValue& v, size_t idx) { v.idx = idx; },
+ [](MyValue& l, MyValue& r) { return l.value < r.value; });
// 0 1 2 3 4 5 6 7 8
int nums[] = { 32, 1, 88, 16, 9, 11, 3, 22, 23 };
for (auto &i : nums)
- q.push(std::make_pair(std::make_pair(i, &i), 0U));
- REQUIRE(q.top().first.first == 1);
- REQUIRE(q.top().first.second == &nums[1]);
- REQUIRE(*q.top().first.second == 1);
+ q.push({ i, &i, 0U });
+ REQUIRE(q.top().value == 1);
+ REQUIRE(q.top().ptr == &nums[1]);
+ REQUIRE(*q.top().ptr == 1);
// Update the top element.
- q.top().first.first = 2;
+ q.top().value = 2;
q.update(1);
- REQUIRE(q.top().first.first == 2);
- REQUIRE(q.top().first.second == &nums[1]);
+ REQUIRE(q.top().value == 2);
+ REQUIRE(q.top().ptr == &nums[1]);
q.pop();
- REQUIRE(q.top().first.first == 3);
- REQUIRE(q.top().first.second == &nums[6]);
+ REQUIRE(q.top().value == 3);
+ REQUIRE(q.top().ptr == &nums[6]);
q.pop();
- REQUIRE(q.top().first.first == 9);
- REQUIRE(q.top().first.second == &nums[4]);
+ REQUIRE(q.top().value == 9);
+ REQUIRE(q.top().ptr == &nums[4]);
q.pop();
- REQUIRE(q.top().first.first == 11);
- REQUIRE(q.top().first.second == &nums[5]);
+ REQUIRE(q.top().value == 11);
+ REQUIRE(q.top().ptr == &nums[5]);
q.pop();
- REQUIRE(q.top().first.first == 16);
- REQUIRE(q.top().first.second == &nums[3]);
+ REQUIRE(q.top().value == 16);
+ REQUIRE(q.top().ptr == &nums[3]);
q.pop();
- REQUIRE(q.top().first.first == 22);
- REQUIRE(q.top().first.second == &nums[7]);
+ REQUIRE(q.top().value == 22);
+ REQUIRE(q.top().ptr == &nums[7]);
q.pop();
- REQUIRE(q.top().first.first == 23);
- REQUIRE(q.top().first.second == &nums[8]);
+ REQUIRE(q.top().value == 23);
+ REQUIRE(q.top().ptr == &nums[8]);
q.pop();
- REQUIRE(q.top().first.first == 32);
- REQUIRE(q.top().first.second == &nums[0]);
+ REQUIRE(q.top().value == 32);
+ REQUIRE(q.top().ptr == &nums[0]);
q.pop();
- REQUIRE(q.top().first.first == 88);
- REQUIRE(q.top().first.second == &nums[2]);
+ REQUIRE(q.top().value == 88);
+ REQUIRE(q.top().ptr == &nums[2]);
q.pop();
REQUIRE(q.empty());
}
SECTION("reschedule to mid range moves element to correct place") {
- auto q = make_miniheap_mutable_priority_queue<std::pair<std::pair<int, int*>, size_t>, 4, false>(
- [](std::pair<std::pair<int, int*>, size_t>& v, size_t idx) { v.second = idx; },
- [](std::pair<std::pair<int, int*>, size_t>& l, std::pair<std::pair<int, int*>, size_t>& r) { return l.first.first < r.first.first; });
+ auto q = make_miniheap_mutable_priority_queue<MyValue, 4, false>(
+ [](MyValue& v, size_t idx) { v.idx = idx; },
+ [](MyValue& l, MyValue& r) { return l.value < r.value; });
// 0 1 2 3 4 5 6 7 8
int nums[] = { 32, 1, 88, 16, 9, 11, 3, 22, 23 };
for (auto& i : nums)
- q.push(std::make_pair(std::make_pair(i, &i), 0U));
- REQUIRE(q.top().first.first == 1);
- REQUIRE(q.top().first.second == &nums[1]);
- REQUIRE(*q.top().first.second == 1);
+ q.push({ i, &i, 0U });
+ REQUIRE(q.top().value == 1);
+ REQUIRE(q.top().ptr == &nums[1]);
+ REQUIRE(*q.top().ptr == 1);
// Update the top element.
- q.top().first.first = 12;
+ q.top().value = 12;
q.update(1);
- REQUIRE(q.top().first.first == 3);
- REQUIRE(q.top().first.second == &nums[6]);
+ REQUIRE(q.top().value == 3);
+ REQUIRE(q.top().ptr == &nums[6]);
q.pop();
- REQUIRE(q.top().first.first == 9);
- REQUIRE(q.top().first.second == &nums[4]);
+ REQUIRE(q.top().value == 9);
+ REQUIRE(q.top().ptr == &nums[4]);
q.pop();
- REQUIRE(q.top().first.first == 11);
- REQUIRE(q.top().first.second == &nums[5]);
+ REQUIRE(q.top().value == 11);
+ REQUIRE(q.top().ptr == &nums[5]);
q.pop();
- REQUIRE(q.top().first.first == 12);
- REQUIRE(q.top().first.second == &nums[1]);
+ REQUIRE(q.top().value == 12);
+ REQUIRE(q.top().ptr == &nums[1]);
q.pop();
- REQUIRE(q.top().first.first == 16);
- REQUIRE(q.top().first.second == &nums[3]);
+ REQUIRE(q.top().value == 16);
+ REQUIRE(q.top().ptr == &nums[3]);
q.pop();
- REQUIRE(q.top().first.first == 22);
- REQUIRE(q.top().first.second == &nums[7]);
+ REQUIRE(q.top().value == 22);
+ REQUIRE(q.top().ptr == &nums[7]);
q.pop();
- REQUIRE(q.top().first.first == 23);
- REQUIRE(q.top().first.second == &nums[8]);
+ REQUIRE(q.top().value == 23);
+ REQUIRE(q.top().ptr == &nums[8]);
q.pop();
- REQUIRE(q.top().first.first == 32);
- REQUIRE(q.top().first.second == &nums[0]);
+ REQUIRE(q.top().value == 32);
+ REQUIRE(q.top().ptr == &nums[0]);
q.pop();
- REQUIRE(q.top().first.first == 88);
- REQUIRE(q.top().first.second == &nums[2]);
+ REQUIRE(q.top().value == 88);
+ REQUIRE(q.top().ptr == &nums[2]);
q.pop();
REQUIRE(q.empty());
}
SECTION("reschedule to last moves element to correct place", "heap")
{
- auto q = make_miniheap_mutable_priority_queue<std::pair<std::pair<int, int*>, size_t>, 4, false>(
- [](std::pair<std::pair<int, int*>, size_t>& v, size_t idx) { v.second = idx; },
- [](std::pair<std::pair<int, int*>, size_t>& l, std::pair<std::pair<int, int*>, size_t>& r) { return l.first.first < r.first.first; });
+ auto q = make_miniheap_mutable_priority_queue<MyValue, 4, false>(
+ [](MyValue& v, size_t idx) { v.idx = idx; },
+ [](MyValue& l, MyValue& r) { return l.value < r.value; });
// 0 1 2 3 4 5 6 7 8
int nums[] = { 32, 1, 88, 16, 9, 11, 3, 22, 23 };
for (auto& i : nums)
- q.push(std::make_pair(std::make_pair(i, &i), 0U));
- REQUIRE(q.top().first.first == 1);
- REQUIRE(q.top().first.second == &nums[1]);
- REQUIRE(*q.top().first.second == 1);
+ q.push({ i, &i, 0U });
+ REQUIRE(q.top().value == 1);
+ REQUIRE(q.top().ptr == &nums[1]);
+ REQUIRE(*q.top().ptr == 1);
// Update the top element.
- q.top().first.first = 89;
+ q.top().value = 89;
q.update(1);
- REQUIRE(q.top().first.first == 3);
- REQUIRE(q.top().first.second == &nums[6]);
+ REQUIRE(q.top().value == 3);
+ REQUIRE(q.top().ptr == &nums[6]);
q.pop();
- REQUIRE(q.top().first.first == 9);
- REQUIRE(q.top().first.second == &nums[4]);
+ REQUIRE(q.top().value == 9);
+ REQUIRE(q.top().ptr == &nums[4]);
q.pop();
- REQUIRE(q.top().first.first == 11);
- REQUIRE(q.top().first.second == &nums[5]);
+ REQUIRE(q.top().value == 11);
+ REQUIRE(q.top().ptr == &nums[5]);
q.pop();
- REQUIRE(q.top().first.first == 16);
- REQUIRE(q.top().first.second == &nums[3]);
+ REQUIRE(q.top().value == 16);
+ REQUIRE(q.top().ptr == &nums[3]);
q.pop();
- REQUIRE(q.top().first.first == 22);
- REQUIRE(q.top().first.second == &nums[7]);
+ REQUIRE(q.top().value == 22);
+ REQUIRE(q.top().ptr == &nums[7]);
q.pop();
- REQUIRE(q.top().first.first == 23);
- REQUIRE(q.top().first.second == &nums[8]);
+ REQUIRE(q.top().value == 23);
+ REQUIRE(q.top().ptr == &nums[8]);
q.pop();
- REQUIRE(q.top().first.first == 32);
- REQUIRE(q.top().first.second == &nums[0]);
+ REQUIRE(q.top().value == 32);
+ REQUIRE(q.top().ptr == &nums[0]);
q.pop();
- REQUIRE(q.top().first.first == 88);
- REQUIRE(q.top().first.second == &nums[2]);
+ REQUIRE(q.top().value == 88);
+ REQUIRE(q.top().ptr == &nums[2]);
q.pop();
- REQUIRE(q.top().first.first == 89);
- REQUIRE(q.top().first.second == &nums[1]);
+ REQUIRE(q.top().value == 89);
+ REQUIRE(q.top().ptr == &nums[1]);
q.pop();
REQUIRE(q.empty());
}