diff options
author | Thomas Lively <tlively@google.com> | 2024-09-03 09:21:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-03 09:21:07 -0700 |
commit | b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9 (patch) | |
tree | 401a90a9b28a625638c2bc9c6f687bb3662862bc /test/gtest | |
parent | 871ff0d4f910b565c15f82e8f3c9aa769b01d286 (diff) | |
download | binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.tar.gz binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.tar.bz2 binaryen-b7cdb8c2110dff5a9b096d766dac04cd8ec04cc9.zip |
[NFC] Change topological sort utilities to functions (#6889)
Previously they were structs and their results were accessed with
`operator*()`, but that was unnecessarily complicated and could lead to
problems with temporary lifetimes being too short. Simplify the
utilities by making them functions. This also allows the wrapper
templates to infer the proper element types automatically.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/topological-orders.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/test/gtest/topological-orders.cpp b/test/gtest/topological-orders.cpp index ba370123d..41e1df483 100644 --- a/test/gtest/topological-orders.cpp +++ b/test/gtest/topological-orders.cpp @@ -102,14 +102,13 @@ TEST(TopologicalOrdersTest, Diamond) { TEST(MinTopologicalSortTest, Empty) { Graph graph(0); - EXPECT_EQ(*MinTopologicalSort(graph), std::vector<size_t>{}); + EXPECT_EQ(TopologicalSort::minSort(graph), std::vector<size_t>{}); } TEST(MinTopologicalSortTest, Unconstrained) { Graph graph(3); - MinTopologicalSort order(graph); std::vector<size_t> expected{0, 1, 2}; - EXPECT_EQ(*MinTopologicalSort(graph), expected); + EXPECT_EQ(TopologicalSort::minSort(graph), expected); } TEST(MinTopologicalSortTest, Reversed) { @@ -117,7 +116,7 @@ TEST(MinTopologicalSortTest, Reversed) { graph[2].push_back(1); graph[1].push_back(0); std::vector<size_t> expected{2, 1, 0}; - EXPECT_EQ(*MinTopologicalSort(graph), expected); + EXPECT_EQ(TopologicalSort::minSort(graph), expected); } TEST(MinTopologicalSortTest, OneBeforeZero) { @@ -125,7 +124,7 @@ TEST(MinTopologicalSortTest, OneBeforeZero) { graph[1].push_back(0); // 2 last because it is greater than 1 and 0 std::vector<size_t> expected{1, 0, 2}; - EXPECT_EQ(*MinTopologicalSort(graph), expected); + EXPECT_EQ(TopologicalSort::minSort(graph), expected); } TEST(MinTopologicalSortTest, TwoBeforeOne) { @@ -133,7 +132,7 @@ TEST(MinTopologicalSortTest, TwoBeforeOne) { graph[2].push_back(1); // 0 first because it is less than 2 and 1 std::vector<size_t> expected{0, 2, 1}; - EXPECT_EQ(*MinTopologicalSort(graph), expected); + EXPECT_EQ(TopologicalSort::minSort(graph), expected); } TEST(MinTopologicalSortTest, TwoBeforeZero) { @@ -141,7 +140,7 @@ TEST(MinTopologicalSortTest, TwoBeforeZero) { graph[2].push_back(0); // 1 first because it is less than 2 and zero is not eligible. std::vector<size_t> expected{1, 2, 0}; - EXPECT_EQ(*MinTopologicalSort(graph), expected); + EXPECT_EQ(TopologicalSort::minSort(graph), expected); } TEST(MinTopologicalSortTest, Strings) { @@ -151,6 +150,5 @@ TEST(MinTopologicalSortTest, Strings) { {"dog", {}}, {"mammal", {"cat", "dog"}}}; std::vector<std::string> expected{"animal", "mammal", "cat", "dog"}; - EXPECT_EQ(*MinTopologicalSortOf<std::string>(graph.begin(), graph.end()), - expected); + EXPECT_EQ(TopologicalSort::minSortOf(graph.begin(), graph.end()), expected); } |