Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | #include "d_range.h" |
| 2 | #include "d_zip.h" |
||
| 3 | #include <array> |
||
| 4 | #include <vector> |
||
| 5 | |||
| 6 | #define BOOST_TEST_DYN_LINK |
||
| 7 | #define BOOST_TEST_MODULE Rebirth zip |
||
| 8 | #include <boost/test/unit_test.hpp> |
||
| 9 | |||
| 10 | /* Test that a zipped range is empty when the component range is empty. |
||
| 11 | */ |
||
| 12 | BOOST_AUTO_TEST_CASE(zip_empty) |
||
| 13 | { |
||
| 14 | bool empty = true; |
||
| 15 | std::array<int, 0> a; |
||
| 16 | for (auto &&v : zip(a)) |
||
| 17 | { |
||
| 18 | (void)v; |
||
| 19 | empty = false; |
||
| 20 | } |
||
| 21 | BOOST_TEST(empty); |
||
| 22 | } |
||
| 23 | |||
| 24 | /* Test that a zipped range is the length of the first sequence. |
||
| 25 | * |
||
| 26 | * Note that there is no test for when the first sequence is longer than |
||
| 27 | * the later ones, since such a test would increment some iterators past |
||
| 28 | * their end. |
||
| 29 | */ |
||
| 30 | BOOST_AUTO_TEST_CASE(zip_length) |
||
| 31 | { |
||
| 32 | unsigned count = 0; |
||
| 33 | std::array<int, 2> a; |
||
| 34 | short b[4]; |
||
| 35 | for (auto &&v : zip(a, b)) |
||
| 36 | { |
||
| 37 | (void)v; |
||
| 38 | ++ count; |
||
| 39 | } |
||
| 40 | BOOST_TEST(count == a.size()); |
||
| 41 | } |
||
| 42 | |||
| 43 | /* Test that a zipped value references the underlying storage. |
||
| 44 | */ |
||
| 45 | BOOST_AUTO_TEST_CASE(zip_passthrough_modifications) |
||
| 46 | { |
||
| 47 | std::array<int, 1> a{{1}}; |
||
| 48 | short b[1]{2}; |
||
| 49 | for (auto &&v : zip(a, b)) |
||
| 50 | { |
||
| 51 | ++ std::get<0>(v); |
||
| 52 | ++ std::get<1>(v); |
||
| 53 | } |
||
| 54 | BOOST_TEST(a[0] == 2); |
||
| 55 | BOOST_TEST(b[0] == 3); |
||
| 56 | } |
||
| 57 | |||
| 58 | /* Test that a zipped range can zip an xrange, and produce the correct |
||
| 59 | * underlying value. |
||
| 60 | */ |
||
| 61 | BOOST_AUTO_TEST_CASE(zip_xrange) |
||
| 62 | { |
||
| 63 | for (auto &&v : zip(xrange(1u))) |
||
| 64 | { |
||
| 65 | BOOST_TEST(std::get<0>(v) == 0); |
||
| 66 | } |
||
| 67 | } |