12#include "../3rdparty/catch2/catch.hpp"
14#include "../misc/alternating_iterator.hpp"
16#include "../safeguards.h"
18TEST_CASE(
"AlternatingIterator tests")
20 auto test_case = [&](
auto input, std::initializer_list<int> expected) {
21 return std::ranges::equal(input, expected);
25 std::initializer_list<const int> raw_sequence_even = {INT_MAX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, INT_MAX};
26 const std::span<const int> sequence_even = std::span{raw_sequence_even.begin() + 1, raw_sequence_even.end() - 1};
28 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 0), { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
29 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 1), { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9 }));
30 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 2), { 2, 1, 3, 0, 4, 5, 6, 7, 8, 9 }));
31 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 3), { 3, 2, 4, 1, 5, 0, 6, 7, 8, 9 }));
32 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 4), { 4, 3, 5, 2, 6, 1, 7, 0, 8, 9 }));
33 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 5), { 5, 4, 6, 3, 7, 2, 8, 1, 9, 0 }));
34 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 6), { 6, 5, 7, 4, 8, 3, 9, 2, 1, 0 }));
35 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 7), { 7, 6, 8, 5, 9, 4, 3, 2, 1, 0 }));
36 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 8), { 8, 7, 9, 6, 5, 4, 3, 2, 1, 0 }));
37 CHECK(test_case(
AlternatingView(sequence_even, sequence_even.begin() + 9), { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }));
40 std::initializer_list<const int> raw_sequence_odd = {INT_MAX, 0, 1, 2, 3, 4, INT_MAX};
41 const std::span<const int> sequence_odd = std::span{raw_sequence_odd.begin() + 1, raw_sequence_odd.end() - 1};
43 CHECK(test_case(
AlternatingView(sequence_odd, sequence_odd.begin() + 0), { 0, 1, 2, 3, 4 }));
44 CHECK(test_case(
AlternatingView(sequence_odd, sequence_odd.begin() + 1), { 1, 0, 2, 3, 4 }));
45 CHECK(test_case(
AlternatingView(sequence_odd, sequence_odd.begin() + 2), { 2, 1, 3, 0, 4 }));
46 CHECK(test_case(
AlternatingView(sequence_odd, sequence_odd.begin() + 3), { 3, 2, 4, 1, 0 }));
47 CHECK(test_case(
AlternatingView(sequence_odd, sequence_odd.begin() + 4), { 4, 3, 2, 1, 0 }));