Skip to content

Commit

Permalink
fix bug in priority_queue==
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKrawisz committed Nov 1, 2022
1 parent f2743db commit 6bbd903
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/data/tools/priority_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ namespace data::tool {

template <functional::tree tree, typename element = element_of<tree>>
bool inline operator==(const priority_queue<tree, element> a, const priority_queue<tree, element> b) {
return a.first() == b.first() && a.rest() == b.rest();
if (data::empty(a) && data::empty(b)) return true;
if (data::empty(a) || data::empty(b)) return false;
if (a.first() != b.first()) return false;
return a.rest() == b.rest();
}

template <functional::tree tree, typename element>
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package_add_test(testTake testTake.cpp)
package_add_test(testSort testSort.cpp)
package_add_test(testLinkedTree testLinkedTree.cpp)
package_add_test(testMap testMap.cpp)
package_add_test(testPriorityQueue testPriorityQueue.cpp)
package_add_test(testForEach testForEach.cpp)
package_add_test(testPolynomial testPolynomial.cpp)
package_add_test(testPermutation testPermutation.cpp)
Expand Down
19 changes: 19 additions & 0 deletions test/testPriorityQueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2019 Daniel Krawisz
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "data/tools.hpp"
#include "gtest/gtest.h"

TEST(PriorityQueueTest, TestPriorityQueue) {
using namespace data;

using pq = priority_queue<int>;

EXPECT_EQ(pq{}, pq{});
EXPECT_EQ(first(pq{} << 1), 1);
EXPECT_NE(pq{} << 1, pq{});
EXPECT_EQ(pq{} << 1 << 2, pq{} << 2 << 1);
EXPECT_EQ(1, first(pq{} << 2 << 1));
}

0 comments on commit 6bbd903

Please sign in to comment.