Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
#include "d_range.h"
2
#include <vector>
3
 
4
#define BOOST_TEST_DYN_LINK
5
#define BOOST_TEST_MODULE Rebirth xrange
6
#include <boost/test/unit_test.hpp>
7
 
8
/* Test that an xrange is empty when the ending bound is 0.
9
 */
10
BOOST_AUTO_TEST_CASE(xrange_empty_0)
11
{
12
        bool empty = true;
13
        for (auto &&v : xrange(0u))
14
        {
15
                (void)v;
16
                empty = false;
17
        }
18
        BOOST_TEST(empty);
19
}
20
 
21
/* Test that an xrange is empty when the start is higher than the end.
22
 */
23
BOOST_AUTO_TEST_CASE(xrange_empty_transposed)
24
{
25
        bool empty = true;
26
        for (auto &&v : xrange(2u, 1u))
27
        {
28
                (void)v;
29
                empty = false;
30
        }
31
        BOOST_TEST(empty);
32
}
33
 
34
/* Test that an xrange produces the correct number of entries.
35
 */
36
BOOST_AUTO_TEST_CASE(xrange_length)
37
{
38
        unsigned count = 0;
39
        constexpr unsigned length = 4u;
40
        for (auto &&v : xrange(length))
41
        {
42
                (void)v;
43
                ++ count;
44
        }
45
        BOOST_TEST(count == length);
46
}
47
 
48
/* Test that an xrange produces the correct values when using an implied
49
 * start of 0.
50
 */
51
BOOST_AUTO_TEST_CASE(xrange_contents)
52
{
53
        std::vector<unsigned> out;
54
        for (auto &&v : xrange(4u))
55
                out.emplace_back(v);
56
        std::vector<unsigned> expected{0, 1, 2, 3};
57
        BOOST_TEST(out == expected);
58
}
59
 
60
/* Test that an xrange produces the correct values when using an
61
 * explicit start.
62
 */
63
BOOST_AUTO_TEST_CASE(xrange_contents_start)
64
{
65
        std::vector<unsigned> out;
66
        for (auto &&v : xrange(2u, 4u))
67
                out.emplace_back(v);
68
        std::vector<unsigned> expected{2, 3};
69
        BOOST_TEST(out == expected);
70
}