From 970854f37aab87d6df10991c9279ea3298b2c988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffan=20S=C3=B8lvsten?= Date: Wed, 23 Oct 2024 11:18:47 +0200 Subject: [PATCH] Replace begin-end output iterator pair with a single iterator Doing it like this follows the STL library. The previous versions of these functions are still available but are deprecated. --- docs/tutorial/functional.md | 10 +- src/adiar/bdd.h | 68 ++-- src/adiar/deprecated.h | 74 +++++ src/adiar/zdd.h | 66 ++-- test/adiar/bdd/test_evaluate.cpp | 463 ++++++++++++--------------- test/adiar/internal/test_dd_func.cpp | 140 ++++---- test/adiar/test_functional.cpp | 6 +- test/adiar/zdd/test_elem.cpp | 226 ++++++------- 8 files changed, 519 insertions(+), 534 deletions(-) diff --git a/docs/tutorial/functional.md b/docs/tutorial/functional.md index 8b58746a9..3a3c55054 100644 --- a/docs/tutorial/functional.md +++ b/docs/tutorial/functional.md @@ -43,20 +43,16 @@ adiar::bdd _ = adiar::bdd_exists(f, xs.begin(), xs.end()); ``` Reversely, one can also parse information from Adiar's algorithms back into -one's own data structures with a pair of iterators. For example, the variables +one's own data structures with an output iterator. For example, the variables within a BDD can be copied (in *ascending* order) into a `std::vector` with the `adiar::bdd_support` function as follows. ```cpp -std::vector xs(adiar::bdd_varcount(f)); +std::vector xs; -adiar::bdd_support(f, xs.begin(), xs.end()); +adiar::bdd_support(f, std::back_inserter(xs)); ``` -Here, we initialise the vector with `adiar::bdd_varcount` many -default-initialized values to be sure that the range `xs.begin()` to `xs.end()` -is big enough to fit the entire result. - Generators and Consumers ================================== diff --git a/src/adiar/bdd.h b/src/adiar/bdd.h index e39ee88ec..dc78f3f35 100644 --- a/src/adiar/bdd.h +++ b/src/adiar/bdd.h @@ -1950,24 +1950,18 @@ namespace adiar /// \param f /// BDD of interest. /// - /// \param begin - /// Single-pass forward iterator for where to place the output. - /// - /// \param end - /// Marks the end for `begin`. - /// - /// \returns An iterator to the first entry that still is left empty. + /// \param iter + /// Single-pass output iterator for where to place the output. /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `f`. + /// \returns The output iterator at its final state. ////////////////////////////////////////////////////////////////////////////////////////////////// - template - ForwardIt - bdd_support(const bdd& f, ForwardIt begin, ForwardIt end) + template >>> + OutputIt + bdd_support(const bdd& f, OutputIt iter) { - bdd_support(f, make_consumer(begin, end)); - return begin; + bdd_support(f, make_consumer(iter)); + return iter; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2078,23 +2072,17 @@ namespace adiar /// BDD of interest. /// /// \param begin - /// Single-pass forward *mutable* iterator for where to place the output. + /// Single-pass output iterator for where to place the output. /// - /// \param end - /// Marks the end for `begin`. - /// - /// \returns An iterator to the first entry that still is left empty. - /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `f`. + /// \returns The output iterator at its final state. ////////////////////////////////////////////////////////////////////////////////////////////////// - template >> - ForwardIt - bdd_satmin(const bdd& f, ForwardIt begin, ForwardIt end) + template >> && !is_convertible>> + OutputIt + bdd_satmin(const bdd& f, OutputIt iter) { - bdd_satmin(f, make_consumer(begin, end)); - return begin; + bdd_satmin(f, make_consumer>(iter)); + return iter; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2181,23 +2169,17 @@ namespace adiar /// BDD of interest. /// /// \param begin - /// Single-pass forward *mutable* iterator for where to place the output. - /// - /// \param end - /// Marks the end for `begin`. + /// Single-pass output iterator for where to place the output. /// - /// \returns An iterator to the first entry that still is left empty. - /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `f`. + /// \returns The output iterator at its final state. ////////////////////////////////////////////////////////////////////////////// - template >> - ForwardIt - bdd_satmax(const bdd& f, ForwardIt begin, ForwardIt end) + template >> && !is_convertible>> + OutputIt + bdd_satmax(const bdd& f, OutputIt iter) { - bdd_satmax(f, make_consumer(begin, end)); - return begin; + bdd_satmax(f, make_consumer>(iter)); + return iter; } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/adiar/deprecated.h b/src/adiar/deprecated.h index 5231bd062..765e70b1e 100644 --- a/src/adiar/deprecated.h +++ b/src/adiar/deprecated.h @@ -5,6 +5,80 @@ namespace adiar { // LCOV_EXCL_START + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief Copy all of the variable labels (in \em ascending order) that occur in the BDD into the + /// given container. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template + [[deprecated("Use an output iterator")]] + ForwardIt + bdd_support(const bdd& f, ForwardIt begin, ForwardIt end) + { + bdd_support(f, make_consumer(begin, end)); + return begin; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief The lexicographically smallest x such that f(x) is true. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template >> + [[deprecated("Use an output iterator (Did you mean to provide values? Use a constant iterator, for now)")]] + ForwardIt + bdd_satmin(const bdd& f, ForwardIt begin, ForwardIt end) + { + bdd_satmin(f, make_consumer(begin, end)); + return begin; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief The lexicographically largest x such that f(x) is true. + ////////////////////////////////////////////////////////////////////////////// + template >> + [[deprecated("Use an output iterator (Did you mean to provide values? Use a constant iterator, for now)")]] + ForwardIt + bdd_satmax(const bdd& f, ForwardIt begin, ForwardIt end) + { + bdd_satmax(f, make_consumer(begin, end)); + return begin; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief Copy all of the variable labels (in \em ascending order) that occur in the family into + /// the given container. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template + [[deprecated("Use an output iterator")]] + ForwardIt + zdd_support(const zdd& A, ForwardIt begin, ForwardIt end) + { + zdd_support(A, make_consumer(begin, end)); + return begin; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief Retrieves the lexicographically smallest set a in A. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template + [[deprecated("Use an output iterator")]] + ForwardIt + zdd_minelem(const zdd& A, ForwardIt begin, ForwardIt end) + { + zdd_minelem(A, make_consumer(begin, end)); + return begin; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////// + /// \brief Retrieves the lexicographically largest set a in A. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template + [[deprecated("Use an output iterator")]] + ForwardIt + zdd_maxelem(const zdd& A, ForwardIt begin, ForwardIt end) + { + zdd_maxelem(A, make_consumer(begin, end)); + return begin; + } + // LCOV_EXCL_STOP } diff --git a/src/adiar/zdd.h b/src/adiar/zdd.h index 7732ba88d..3b46689c5 100644 --- a/src/adiar/zdd.h +++ b/src/adiar/zdd.h @@ -1480,23 +1480,17 @@ namespace adiar /// ZDD of interest. /// /// \param begin - /// Single-pass forward iterator for where to place the output. - /// - /// \param end - /// Marks the end for `begin`. - /// - /// \returns An iterator to the first entry that still is left empty. + /// Single-pass output iterator for where to place the output. /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `A`. + /// \returns The output iterator at its final state. ////////////////////////////////////////////////////////////////////////////////////////////////// - template - ForwardIt - zdd_support(const zdd& A, ForwardIt begin, ForwardIt end) + template >>> + OutputIt + zdd_support(const zdd& A, OutputIt iter) { - zdd_support(A, make_consumer(begin, end)); - return begin; + zdd_support(A, make_consumer(iter)); + return iter; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1597,21 +1591,15 @@ namespace adiar /// \param begin /// Single-pass forward iterator for where to place the output. /// - /// \param end - /// Marks the end for `begin`. - /// - /// \returns An iterator to the first entry that still is left empty. - /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `A`. - ////////////////////////////////////////////////////////////////////////////// - template - ForwardIt - zdd_minelem(const zdd& A, ForwardIt begin, ForwardIt end) + /// \returns The output iterator at its final state. + ////////////////////////////////////////////////////////////////////////////////////////////////// + template >>> + OutputIt + zdd_minelem(const zdd& A, OutputIt iter) { - zdd_minelem(A, make_consumer(begin, end)); - return begin; + zdd_minelem(A, make_consumer(iter)); + return iter; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1649,23 +1637,17 @@ namespace adiar /// Set of sets of interest. /// /// \param begin - /// Single-pass forward iterator for where to place the output. + /// Single-pass output iterator for where to place the output. /// - /// \param end - /// Marks the end for `begin`. - /// - /// \returns An iterator to the first entry that still is left empty. - /// - /// \throws out_of_range - /// If the distance between `begin` and `end` is not big enough to contain all variables in - /// `A`. + /// \returns The output iterator at its final state. ////////////////////////////////////////////////////////////////////////////////////////////////// - template - ForwardIt - zdd_maxelem(const zdd& A, ForwardIt begin, ForwardIt end) + template >>> + OutputIt + zdd_maxelem(const zdd& A, OutputIt iter) { - zdd_maxelem(A, make_consumer(begin, end)); - return begin; + zdd_maxelem(A, make_consumer(iter)); + return iter; } /// \} diff --git a/test/adiar/bdd/test_evaluate.cpp b/test/adiar/bdd/test_evaluate.cpp index 0233ab681..74bd02f6d 100644 --- a/test/adiar/bdd/test_evaluate.cpp +++ b/test/adiar/bdd/test_evaluate.cpp @@ -1,5 +1,7 @@ #include "../../test.h" +#include + go_bandit([]() { describe("adiar/bdd/evaluate.cpp", []() { { // bdd_eval @@ -2020,167 +2022,148 @@ go_bandit([]() { }); }); - describe("bdd_satmin(const bdd&, MutIter, MutIter)", [&]() { - using buffer_type = std::vector>; - - const buffer_type::value_type buffer_default(bdd::max_label + 1, false); - const size_t buffer_size = 4; - - it("outputs nothing in buffer for false terminal", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd_F, buffer.begin(), buffer.end()); + describe("bdd_satmin(const bdd&, OutputIter)", [&]() { + using pair_type = pair; + using output_vector = std::vector; - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + it("outputs [] for false terminal", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd_F, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {21, true}; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{21, true})); }); - it("outputs nothing in buffer for true terminal", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd_T, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + it("outputs [] for true terminal", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd_T, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {42, false}; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{42, false})); }); - it("outputs {x0, true} for [0]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd_0, buffer.begin(), buffer.end()); + it("outputs [{x0, true}] for [0]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd_0, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {42, false}; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{42, false})); }); - it("outputs {x0, false} for [~0]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd(bdd_0, true), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); + it("outputs [{x0, false}] for [~0]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd(bdd_0, true), std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); - it("throws 'out_of_range' if buffer is too small [0]", [&]() { - buffer_type buffer(0, buffer_default); - AssertThrows(out_of_range, bdd_satmin(bdd_0, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = {21, true}; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{21, true})); }); - it("outputs expected values into buffer for [1]", [&]() { - buffer_type buffer(buffer_size, buffer_default); + it("outputs [{0, false}, {1, false}, {2, true}, {3, true}] for [1]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd_1, std::back_inserter(out)); - auto ret = bdd_satmin(bdd_1, buffer.begin(), buffer.end()); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{1, false})); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, true})); + AssertThat(out.at(3), Is().EqualTo(pair_type{3, true})); - AssertThat(ret, Is().EqualTo(buffer.begin() + 4)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; - expected.at(1) = { 1, false }; - expected.at(2) = { 2, true }; - expected.at(3) = { 3, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {42, true}; + AssertThat(out.size(), Is().EqualTo(5u)); + AssertThat(out.at(3), Is().EqualTo(pair_type{3, true})); + AssertThat(out.at(4), Is().EqualTo(pair_type{42, true})); }); - it("outputs expected values into buffer for [~1]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd(bdd_1, true), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 3)); + it("outputs [{0, false}, {1, false}, {2, false}] for [~1]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd(bdd_1, true), std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; - expected.at(1) = { 1, false }; - expected.at(2) = { 2, false }; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{1, false})); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, false})); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {21, false}; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, false})); + AssertThat(out.at(3), Is().EqualTo(pair_type{21, false})); }); - it("throws 'out_of_range' if buffer is too small [1]", [&]() { - buffer_type buffer(1, buffer_default); - AssertThrows(out_of_range, bdd_satmin(bdd_1, buffer.begin(), buffer.end())); - }); - - it("outputs expected values into buffer for [4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd_4, buffer.begin(), buffer.end()); + it("outputs [{0, false}, {2, false}] for [4]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd_4, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, false})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; - expected.at(1) = { 2, false }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {8, false}; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, false})); + AssertThat(out.at(2), Is().EqualTo(pair_type{8, false})); }); - it("outputs expected values into buffer for [~4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd(bdd_4, true), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 3)); + it("outputs [{0, false}, {2, true}, {3, true}] for [~4]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd(bdd_4, true), std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; - expected.at(1) = { 2, true }; - expected.at(2) = { 3, true }; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, true})); + AssertThat(out.at(2), Is().EqualTo(pair_type{3, true})); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {4, false}; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(pair_type{3, true})); + AssertThat(out.at(3), Is().EqualTo(pair_type{4, false})); }); - it("outputs expected values into buffer for [4(+1)]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmin(bdd(bdd_4, false, +1), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 1, false }; - expected.at(1) = { 3, false }; + it("outputs [{1, false}, {3, false}] for [4(+1)]", [&]() { + output_vector out; + auto iter = bdd_satmin(bdd(bdd_4, false, +1), std::back_inserter(out)); + + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{1, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{3, false})); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [~4]", [&]() { - buffer_type buffer(2, buffer_default); - AssertThrows(out_of_range, bdd_satmin(bdd(bdd_4, true), buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = {5, false}; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(pair_type{3, false})); + AssertThat(out.at(2), Is().EqualTo(pair_type{5, false})); }); }); @@ -3698,173 +3681,149 @@ go_bandit([]() { }); }); - describe("bdd_satmax(const bdd&, MutIter, MutIter)", [&]() { - using buffer_type = std::vector>; - - const buffer_type::value_type buffer_default(bdd::max_label + 1, false); - const size_t buffer_size = 4; + describe("bdd_satmax(const bdd&, OutputIter)", [&]() { + using pair_type = pair; + using output_vector = std::vector; it("outputs nothing in buffer for false terminal", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd_F, buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd_F, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - buffer_type expected(buffer_size, buffer_default); - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {21, true}; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{21, true})); }); it("outputs nothing in buffer for true terminal", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd_T, buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd_T, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - buffer_type expected(buffer_size, buffer_default); - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {42, true}; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{42, true})); }); it("outputs {x0, true} for [0]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd_0, buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd_0, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {42, true}; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{42, true})); }); it("outputs {x0, false} for [~0]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd(bdd_0, true), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, false }; + output_vector out; + auto iter = bdd_satmax(bdd(bdd_0, true), std::back_inserter(out)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); - it("throws 'out_of_range' if buffer is too small [0]", [&]() { - buffer_type buffer(0, buffer_default); - AssertThrows(out_of_range, bdd_satmax(bdd_0, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = {8, false}; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, false})); + AssertThat(out.at(1), Is().EqualTo(pair_type{8, false})); }); it("outputs expected values into buffer for [2]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd_2, buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd_2, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - expected.at(1) = { 2, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {4, false}; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, true})); + AssertThat(out.at(2), Is().EqualTo(pair_type{4, false})); }); it("outputs expected values into buffer for [~2]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd(bdd_2, true), buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd(bdd_2, true), std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 3)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{2, false})); + AssertThat(out.at(2), Is().EqualTo(pair_type{3, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - expected.at(1) = { 2, false }; - expected.at(2) = { 3, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [2]", [&]() { - buffer_type buffer(1, buffer_default); - AssertThrows(out_of_range, bdd_satmax(bdd_2, buffer.begin(), buffer.end())); - }); - - it("throws 'out_of_range' if buffer is too small [~2]", [&]() { - buffer_type buffer(2, buffer_default); - AssertThrows(out_of_range, bdd_satmax(bdd(bdd_2, true), buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = {4, false}; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(pair_type{3, true})); + AssertThat(out.at(3), Is().EqualTo(pair_type{4, false})); }); it("outputs expected values into buffer for [4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd_4, buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd_4, std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 3)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{1, true})); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - expected.at(1) = { 1, true }; - expected.at(2) = { 2, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {3, false}; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, true})); + AssertThat(out.at(3), Is().EqualTo(pair_type{3, false})); }); it("outputs expected values into buffer for [~4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd(bdd_4, true), buffer.begin(), buffer.end()); + output_vector out; + auto iter = bdd_satmax(bdd(bdd_4, true), std::back_inserter(out)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 4)); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{0, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{1, true})); + AssertThat(out.at(2), Is().EqualTo(pair_type{2, false})); + AssertThat(out.at(3), Is().EqualTo(pair_type{3, true})); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 0, true }; - expected.at(1) = { 1, true }; - expected.at(2) = { 2, false }; - expected.at(3) = { 3, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = {4, false}; + AssertThat(out.size(), Is().EqualTo(5u)); + AssertThat(out.at(3), Is().EqualTo(pair_type{3, true})); + AssertThat(out.at(4), Is().EqualTo(pair_type{4, false})); }); it("outputs expected values into buffer for [4(+2)]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = bdd_satmax(bdd(bdd_4, false, +2), buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 3)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = { 2, true }; - expected.at(1) = { 3, true }; - expected.at(2) = { 4, true }; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [~4]", [&]() { - buffer_type buffer(2, buffer_default); - AssertThrows(out_of_range, bdd_satmax(bdd(bdd_4, true), buffer.begin(), buffer.end())); + output_vector out; + auto iter = bdd_satmax(bdd(bdd_4, false, +2), std::back_inserter(out)); + + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(pair_type{2, true})); + AssertThat(out.at(1), Is().EqualTo(pair_type{3, true})); + AssertThat(out.at(2), Is().EqualTo(pair_type{4, true})); + + // Check state of 'iter' + iter = {5, true}; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(pair_type{4, true})); + AssertThat(out.at(3), Is().EqualTo(pair_type{5, true})); }); }); } // bdd_satmin, bdd_satmax diff --git a/test/adiar/internal/test_dd_func.cpp b/test/adiar/internal/test_dd_func.cpp index bcf4f2021..99b0c294a 100644 --- a/test/adiar/internal/test_dd_func.cpp +++ b/test/adiar/internal/test_dd_func.cpp @@ -2,6 +2,8 @@ #include +#include + go_bandit([]() { describe("adiar/internal/dd_func.h", []() { const ptr_uint64 false_ptr = ptr_uint64(false); @@ -51,100 +53,122 @@ go_bandit([]() { } describe("dd_support(f, cb)", [&]() { - // TODO + it("returns [1,3,4] for a BDD with multiple nodes", [&]() { + std::vector out; + + bdd_support(bdd_file, [&out](auto x) { out.push_back(x); }); + + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(1)); + AssertThat(out.at(1), Is().EqualTo(3)); + AssertThat(out.at(2), Is().EqualTo(4)); + }); + + it("returns [0,1,2] for a ZDD with multiple nodes", [&]() { + std::vector out; + + zdd_support(zdd_file, [&out](auto x) { out.push_back(x); }); + + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(0)); + AssertThat(out.at(1), Is().EqualTo(1)); + AssertThat(out.at(2), Is().EqualTo(2)); + }); }); describe("dd_support(f, begin, end)", [&]() { it("does not write anything for BDD false terminal", [&]() { - std::vector out(42, -1); + std::vector out; - auto it_b = out.begin(); - auto it_e = out.end(); + auto iter = bdd_support(terminal_F, std::back_inserter(out)); - const auto out_it = bdd_support(terminal_F, it_b, it_e); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - AssertThat(out_it, Is().EqualTo(it_b)); - AssertThat(*it_b, Is().EqualTo(-1)); + // Check state of 'iter' + iter = 42; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(42)); }); - it("returns empty file for a ZDD true terminal", [&]() { - std::vector out(42, -1); + it("does not write anything for ZDD true terminal", [&]() { + std::vector out; - auto it_b = out.begin(); - auto it_e = out.end(); + auto iter = zdd_support(terminal_T, std::back_inserter(out)); - const auto out_it = zdd_support(terminal_T, it_b, it_e); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - AssertThat(out_it, Is().EqualTo(it_b)); - AssertThat(*it_b, Is().EqualTo(-1)); + // Check state of 'iter' + iter = 8; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(8)); }); it("returns [0] for a ZDD with one node (label 0)", [&]() { - std::vector out(42, -1); + std::vector out; - auto it_b = out.begin(); - auto it_e = out.end(); + auto iter = zdd_support(x0, std::back_inserter(out)); - const auto out_it = zdd_support(x0, it_b, it_e); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(0)); - AssertThat(out_it, Is().EqualTo(it_b + 1)); - AssertThat(*it_b, Is().EqualTo(0)); - AssertThat(*out_it, Is().EqualTo(-1)); + // Check state of 'iter' + iter = 8; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(1), Is().EqualTo(8)); }); it("returns [42] for a ZDD with one node (label 42)", [&]() { - std::vector out(42, -1); + std::vector out; - auto it_b = out.begin(); - auto it_e = out.end(); + auto iter = zdd_support(x42, std::back_inserter(out)); - const auto out_it = zdd_support(x42, it_b, it_e); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(42)); - AssertThat(out_it, Is().EqualTo(it_b + 1)); - AssertThat(*it_b, Is().EqualTo(42)); - AssertThat(*out_it, Is().EqualTo(-1)); + // Check state of 'iter' + iter = 8; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(1), Is().EqualTo(8)); }); it("returns [1,3,4] for a BDD with multiple nodes", [&]() { - std::vector out(42, -1); + std::vector out; - auto it_b = out.begin(); - auto it_e = out.end(); + auto iter = bdd_support(bdd_file, std::back_inserter(out)); - const auto out_it = bdd_support(bdd_file, it_b, it_e); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(1)); + AssertThat(out.at(1), Is().EqualTo(3)); + AssertThat(out.at(2), Is().EqualTo(4)); - AssertThat(*(it_b + 0), Is().EqualTo(1)); - AssertThat(*(it_b + 1), Is().EqualTo(3)); - AssertThat(*(it_b + 2), Is().EqualTo(4)); - - AssertThat(out_it, Is().EqualTo(it_b + 3)); - AssertThat(*out_it, Is().EqualTo(-1)); + // Check state of 'iter' + iter = 8; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(3), Is().EqualTo(8)); }); it("returns [0,1,2] for a ZDD with multiple nodes", [&]() { - std::vector out(42, -1); - - auto it_b = out.begin(); - auto it_e = out.end(); + std::vector out; - const auto out_it = zdd_support(zdd_file, it_b, it_e); + auto iter = zdd_support(zdd_file, std::back_inserter(out)); - AssertThat(*(it_b + 0), Is().EqualTo(0)); - AssertThat(*(it_b + 1), Is().EqualTo(1)); - AssertThat(*(it_b + 2), Is().EqualTo(2)); - - AssertThat(out_it, Is().EqualTo(it_b + 3)); - AssertThat(*out_it, Is().EqualTo(-1)); - }); - - it("throws if range is too small for BDD", [&]() { - std::vector out(1, -1); - AssertThrows(out_of_range, bdd_support(bdd_file, out.begin(), out.end())); - }); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(0), Is().EqualTo(0)); + AssertThat(out.at(1), Is().EqualTo(1)); + AssertThat(out.at(2), Is().EqualTo(2)); - it("throws if range is too small for ZDD", [&]() { - std::vector out(1, -1); - AssertThrows(out_of_range, zdd_support(zdd_file, out.begin(), out.end())); + // Check state of 'iter' + iter = 8; + AssertThat(out.size(), Is().EqualTo(4u)); + AssertThat(out.at(3), Is().EqualTo(8)); }); }); diff --git a/test/adiar/test_functional.cpp b/test/adiar/test_functional.cpp index 3372e075c..82194f851 100644 --- a/test/adiar/test_functional.cpp +++ b/test/adiar/test_functional.cpp @@ -1,8 +1,8 @@ #include "../test.h" -#include -#include -#include +#include +#include +#include go_bandit([]() { describe("adiar/functional.h", []() { diff --git a/test/adiar/zdd/test_elem.cpp b/test/adiar/zdd/test_elem.cpp index c88a4caf6..373ccae82 100644 --- a/test/adiar/zdd/test_elem.cpp +++ b/test/adiar/zdd/test_elem.cpp @@ -1,5 +1,7 @@ #include "../../test.h" +#include + go_bandit([]() { describe("adiar/zdd/elem.cpp", [&]() { shared_levelized_file zdd_F; @@ -348,94 +350,79 @@ go_bandit([]() { }); }); - describe("zdd_minelem(A, begin, end)", [&]() { - using buffer_type = std::vector; - - const buffer_type::value_type buffer_default(zdd::max_label + 1); - const size_t buffer_size = 4; - - it("outputs { } in buffer for { Ø }", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_minelem(zdd_T, buffer.begin(), buffer.end()); + describe("zdd_minelem(A, iter)", [&]() { + using output_type = std::vector; - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + it("outputs {} for { Ø }", [&]() { + output_type out; + auto iter = zdd_minelem(zdd_T, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = 21; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(21u)); }); - it("outputs { 1 } in buffer for [1]", [&]() { - buffer_type buffer(buffer_size, buffer_default); + it("outputs {1} in buffer for [1]", [&]() { + output_type out; + auto iter = zdd_minelem(zdd_1, std::back_inserter(out)); - auto ret = zdd_minelem(zdd_1, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 1; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(1u)); - it("throws 'out_of_range' if buffer is too small [1]", [&]() { - buffer_type buffer(0, buffer_default); - AssertThrows(out_of_range, zdd_minelem(zdd_1, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = 2; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(1u)); + AssertThat(out.at(1), Is().EqualTo(2u)); }); it("outputs { } in buffer for [2]", [&]() { - buffer_type buffer(buffer_size, buffer_default); + output_type out; + auto iter = zdd_minelem(zdd_2, std::back_inserter(out)); - auto ret = zdd_minelem(zdd_2, buffer.begin(), buffer.end()); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); - - buffer_type expected(buffer_size, buffer_default); - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = 4; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(4u)); }); it("outputs { 2,4 } in buffer for [3]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_minelem(zdd_3, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); + output_type out; + auto iter = zdd_minelem(zdd_3, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 2; - expected.at(1) = 4; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(2u)); + AssertThat(out.at(1), Is().EqualTo(4u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [3]", [&]() { - buffer_type buffer(1, buffer_default); - AssertThrows(out_of_range, zdd_minelem(zdd_3, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = 6; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(4u)); + AssertThat(out.at(2), Is().EqualTo(6u)); }); it("outputs { 1 } in buffer for [4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_minelem(zdd_4, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); + output_type out; + auto iter = zdd_minelem(zdd_4, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 1; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(1u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = 2; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(1u)); + AssertThat(out.at(1), Is().EqualTo(2u)); }); }); @@ -663,86 +650,67 @@ go_bandit([]() { }); }); - describe("zdd_maxelem(A, begin, end)", [&]() { - using buffer_type = std::vector; - - const buffer_type::value_type buffer_default(zdd::max_label + 1); - const size_t buffer_size = 4; + describe("zdd_maxelem(A, iter)", [&]() { + using output_type = std::vector; it("outputs { } in buffer for { Ø }", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_maxelem(zdd_T, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 0)); + output_type out; + auto iter = zdd_maxelem(zdd_T, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(0u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } + // Check state of 'iter' + iter = 2; + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(2u)); }); it("outputs { 0,2 } in buffer for [1]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_maxelem(zdd_1, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); + output_type out; + auto iter = zdd_maxelem(zdd_1, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 0; - expected.at(1) = 2; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(0u)); + AssertThat(out.at(1), Is().EqualTo(2u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [1]", [&]() { - buffer_type buffer(1, buffer_default); - AssertThrows(out_of_range, zdd_maxelem(zdd_1, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = 4; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(2u)); + AssertThat(out.at(2), Is().EqualTo(4u)); }); it("outputs { 1 } in buffer for [2]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_maxelem(zdd_2, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 1)); + output_type out; + auto iter = zdd_maxelem(zdd_2, std::back_inserter(out)); - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 1; + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(1u)); + AssertThat(out.at(0), Is().EqualTo(1u)); - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [2]", [&]() { - buffer_type buffer(0, buffer_default); - AssertThrows(out_of_range, zdd_maxelem(zdd_2, buffer.begin(), buffer.end())); + // Check state of 'iter' + iter = 42; + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(1u)); + AssertThat(out.at(1), Is().EqualTo(42u)); }); it("outputs { 0,1 } in buffer for [4]", [&]() { - buffer_type buffer(buffer_size, buffer_default); - - auto ret = zdd_maxelem(zdd_4, buffer.begin(), buffer.end()); - - AssertThat(ret, Is().EqualTo(buffer.begin() + 2)); - - buffer_type expected(buffer_size, buffer_default); - expected.at(0) = 0; - expected.at(1) = 1; - - for (size_t i = 0; i < buffer_size; ++i) { - AssertThat(buffer.at(i), Is().EqualTo(expected.at(i))); - } - }); - - it("throws 'out_of_range' if buffer is too small [4]", [&]() { - buffer_type buffer(1, buffer_default); - AssertThrows(out_of_range, zdd_maxelem(zdd_4, buffer.begin(), buffer.end())); + output_type out; + auto iter = zdd_maxelem(zdd_4, std::back_inserter(out)); + + // Check state of 'out' + AssertThat(out.size(), Is().EqualTo(2u)); + AssertThat(out.at(0), Is().EqualTo(0u)); + AssertThat(out.at(1), Is().EqualTo(1u)); + + // Check state of 'iter' + iter = 2; + AssertThat(out.size(), Is().EqualTo(3u)); + AssertThat(out.at(1), Is().EqualTo(1u)); + AssertThat(out.at(2), Is().EqualTo(2u)); }); }); });