From c1b6bd0500c093864859a296c32d068148c84a4d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 26 Jul 2017 22:48:39 +0100 Subject: [PATCH] Add unit test for backwards iteration. --- test/unit/test_sequence_range.cpp | 35 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/test/unit/test_sequence_range.cpp b/test/unit/test_sequence_range.cpp index 96bb7a0..8b6de4b 100644 --- a/test/unit/test_sequence_range.cpp +++ b/test/unit/test_sequence_range.cpp @@ -26,9 +26,6 @@ TEST(vwr, vector_iterator) { ivec3 from(100, 200, 300); ivec3 to(102, 203, 304); - auto seq = increasing_sequence_range(from, to); - auto it = seq.begin(); - auto it_end = seq.end(); std::array expected{ ivec3(100, 200, 300), @@ -56,13 +53,33 @@ TEST(vwr, vector_iterator) { ivec3(100, 202, 303), ivec3(101, 202, 303) }; - std::vector results; - for (; it != it_end; ++it) { - results.push_back(*it); + + { + auto seq = increasing_sequence_range(from, to); + auto it = seq.begin(); + auto it_end = seq.end(); + + std::vector results; + for (; it != it_end; ++it) { + results.push_back(*it); + } + + EXPECT_EQ(expected.size(), results.size()); + for (std::size_t z = 0; z < expected.size(); ++z) { + EXPECT_EQ(expected[z], results[z]); + } } - EXPECT_EQ(expected.size(), results.size()); - for (std::size_t z = 0; z < expected.size(); ++z) { - EXPECT_EQ(expected[z], results[z]); + { + using dec_sequence_range = sequence_range, std::greater, 0, 1, 2>; + std::vector results; + for (auto& itm : dec_sequence_range(to, from)) { + results.push_back(itm); + } + + EXPECT_EQ(expected.size(), results.size()); + for (std::size_t z = 0; z < expected.size(); ++z) { + EXPECT_EQ(expected[z] + 1, results[results.size() - 1 - z]); + } } }