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 15:05:30 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-07-09 15:05:30 +0300
commit3a9857e493141ceb9e38d58990796424db00d345 (patch)
tree01f9ef7c64be6617a17113b3a6fe3e62637ac595 /tests/libslic3r
parentd8a0b111574275ee7b156a07dd3d0fefdbf61f53 (diff)
Our friendly GCC does not consider std::pair<int, int> trivially
copiable either, while everybody else does. Shame on GCC.
Diffstat (limited to 'tests/libslic3r')
-rw-r--r--tests/libslic3r/test_mutable_priority_queue.cpp86
1 files changed, 46 insertions, 40 deletions
diff --git a/tests/libslic3r/test_mutable_priority_queue.cpp b/tests/libslic3r/test_mutable_priority_queue.cpp
index 2b446b9c4..37b244432 100644
--- a/tests/libslic3r/test_mutable_priority_queue.cpp
+++ b/tests/libslic3r/test_mutable_priority_queue.cpp
@@ -54,12 +54,18 @@ TEST_CASE("Skip addressing", "[MutableSkipHeapPriorityQueue]") {
}
}
+struct ValueIndexPair
+{
+ int value;
+ size_t idx = 0;
+};
+
template<size_t block_size = 16>
static auto make_test_priority_queue()
{
- return make_miniheap_mutable_priority_queue<std::pair<int, size_t>, block_size, false>(
- [](std::pair<int, size_t> &v, size_t idx){ v.second = idx; },
- [](std::pair<int, size_t> &l, std::pair<int, size_t> &r){ return l.first < r.first; });
+ return make_miniheap_mutable_priority_queue<ValueIndexPair, block_size, false>(
+ [](ValueIndexPair &v, size_t idx){ v.idx = idx; },
+ [](ValueIndexPair &l, ValueIndexPair &r){ return l.value < r.value; });
}
TEST_CASE("Mutable priority queue - basic tests", "[MutableSkipHeapPriorityQueue]") {
@@ -70,18 +76,18 @@ TEST_CASE("Mutable priority queue - basic tests", "[MutableSkipHeapPriorityQueue
}
SECTION("an empty queue is not empty when one element is inserted") {
auto q = make_test_priority_queue();
- q.push(std::make_pair(1, 0U));
+ q.push({ 1 });
REQUIRE(!q.empty());
REQUIRE(q.size() == 1);
}
SECTION("a queue with one element has it on top") {
auto q = make_test_priority_queue();
- q.push(std::make_pair(8, 0U));
- REQUIRE(q.top().first == 8);
+ q.push({ 8 });
+ REQUIRE(q.top().value == 8);
}
SECTION("a queue with one element becomes empty when popped") {
auto q = make_test_priority_queue();
- q.push(std::make_pair(9, 0U));
+ q.push({ 9 });
q.pop();
REQUIRE(q.empty());
REQUIRE(q.size() == 0);
@@ -89,22 +95,22 @@ TEST_CASE("Mutable priority queue - basic tests", "[MutableSkipHeapPriorityQueue
SECTION("insert sorted stays sorted") {
auto q = make_test_priority_queue();
for (auto i : { 1, 2, 3, 4, 5, 6, 7, 8 })
- q.push(std::make_pair(i, 0U));
- REQUIRE(q.top().first == 1);
+ q.push({ i });
+ REQUIRE(q.top().value == 1);
q.pop();
- REQUIRE(q.top().first == 2);
+ REQUIRE(q.top().value == 2);
q.pop();
- REQUIRE(q.top().first == 3);
+ REQUIRE(q.top().value == 3);
q.pop();
- REQUIRE(q.top().first == 4);
+ REQUIRE(q.top().value == 4);
q.pop();
- REQUIRE(q.top().first == 5);
+ REQUIRE(q.top().value == 5);
q.pop();
- REQUIRE(q.top().first == 6);
+ REQUIRE(q.top().value == 6);
q.pop();
- REQUIRE(q.top().first == 7);
+ REQUIRE(q.top().value == 7);
q.pop();
- REQUIRE(q.top().first == 8);
+ REQUIRE(q.top().value == 8);
q.pop();
REQUIRE(q.empty());
}
@@ -116,14 +122,14 @@ TEST_CASE("Mutable priority queue - basic tests", "[MutableSkipHeapPriorityQueue
int n[36000];
for (auto& i : n) {
i = dist(gen);
- q.push(std::make_pair(i, 0U));
+ q.push({ i });
}
REQUIRE(!q.empty());
REQUIRE(q.size() == 36000);
std::sort(std::begin(n), std::end(n));
for (auto i : n) {
- REQUIRE(q.top().first == i);
+ REQUIRE(q.top().value == i);
q.pop();
}
REQUIRE(q.empty());
@@ -277,35 +283,35 @@ TEST_CASE("Mutable priority queue - reshedule first", "[MutableSkipHeapPriorityQ
}
SECTION("reschedule top of 2 elements to last") {
auto q = make_test_priority_queue<8>();
- q.push(std::make_pair(1, 0U));
- q.push(std::make_pair(2, 0U));
- REQUIRE(q.top().first == 1);
+ q.push({ 1 });
+ q.push({ 2 });
+ REQUIRE(q.top().value == 1);
// Update the top element.
- q.top().first = 3;
+ q.top().value = 3;
q.update(1);
- REQUIRE(q.top().first == 2);
+ REQUIRE(q.top().value == 2);
}
SECTION("reschedule top of 3 elements left to 2nd") {
auto q = make_test_priority_queue<8>();
- q.push(std::make_pair(1, 0U));
- q.push(std::make_pair(2, 0U));
- q.push(std::make_pair(4, 0U));
- REQUIRE(q.top().first == 1);
+ q.push({ 1 });
+ q.push({ 2 });
+ q.push({ 4 });
+ REQUIRE(q.top().value == 1);
// Update the top element.
- q.top().first = 3;
+ q.top().value = 3;
q.update(1);
- REQUIRE(q.top().first == 2);
+ REQUIRE(q.top().value == 2);
}
SECTION("reschedule top of 3 elements right to 2nd") {
auto q = make_test_priority_queue<8>();
- q.push(std::make_pair(1, 0U));
- q.push(std::make_pair(4, 0U));
- q.push(std::make_pair(2, 0U));
- REQUIRE(q.top().first == 1);
+ q.push({ 1 });
+ q.push({ 4 });
+ q.push({ 2 });
+ REQUIRE(q.top().value == 1);
// Update the top element.
- q.top().first = 3;
+ q.top().value = 3;
q.update(1);
- REQUIRE(q.top().first == 2);
+ REQUIRE(q.top().value == 2);
}
SECTION("reschedule top random gives same resultas pop/push") {
std::random_device rd;
@@ -317,16 +323,16 @@ TEST_CASE("Mutable priority queue - reshedule first", "[MutableSkipHeapPriorityQ
for (size_t outer = 0; outer < 100; ++ outer) {
int num = gen();
- pq.push(std::make_pair(num, 0U));
- stdq.push(num);
+ pq.push({ num });
+ stdq.push({ num });
for (size_t inner = 0; inner < 100; ++ inner) {
int newval = gen();
// Update the top element.
- pq.top().first = newval;
+ pq.top().value = newval;
pq.update(1);
stdq.pop();
- stdq.push(newval);
- auto n = pq.top().first;
+ stdq.push({ newval });
+ auto n = pq.top().value;
auto sn = stdq.top();
REQUIRE(sn == n);
}