File: map_test_case_test.cpp

package info (click to toggle)
cataclysm-dda 0.H-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 710,808 kB
  • sloc: cpp: 524,019; python: 11,580; sh: 1,228; makefile: 1,169; xml: 507; javascript: 150; sql: 56; exp: 41; perl: 37
file content (144 lines) | stat: -rw-r--r-- 3,987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <array>
#include <iterator>

#include "map_test_case.h"

// test some of the map_test_case helpers
TEST_CASE( "map_test_case_common", "[map_test_case]" )
{
    using namespace map_test_case_common;
    using tile = map_test_case::tile;

    auto test_tile = []( int c ) {
        tile t;
        t.setup_c = c;
        return t;
    };

    SECTION( "|| and &&" ) {
        tile_predicate f_positive = []( tile t ) {
            return t.setup_c > 0;
        };
        tile_predicate f_negative = []( tile t ) {
            return t.setup_c < 0;
        };
        tile_predicate f_less_than_five = []( tile t ) {
            return t.setup_c < 5;
        };

        CHECK( ( f_positive && f_less_than_five )( test_tile( 3 ) ) );
        CHECK_FALSE( ( f_positive && f_less_than_five )( test_tile( -1 ) ) );
        CHECK_FALSE( ( f_positive && f_less_than_five )( test_tile( 6 ) ) );

        CHECK( ( f_positive || f_less_than_five )( test_tile( -1 ) ) );
        CHECK( ( f_positive || f_less_than_five )( test_tile( 6 ) ) );
        CHECK_FALSE( ( f_positive || f_negative )( test_tile( 0 ) ) );
    }
    SECTION( "a && a && a" ) {
        tile_predicate f_true = []( auto ) {
            return true;
        };
        tile_predicate f_false = []( auto ) {
            return false;
        };

        CHECK( ( f_true && f_true && f_true )( {} ) );
        CHECK_FALSE( ( f_true && f_true && f_false )( {} ) );
        CHECK( ( f_true || f_false || f_false )( {} ) );
        CHECK( ( f_false || f_false || f_true )( {} ) );
    }
    SECTION( "inc + inc + inc" ) {
        int counter = 0;
        tile_predicate inc = [&]( auto ) {
            counter++;
            return true;
        };
        map_test_case_common::tile_predicate f = inc + inc + inc;
        CHECK( counter == 0 );
        f( {} );
        CHECK( counter == 3 );
    }
}

// checks the consistency of all transformations
// and valid coordinate calculation
TEST_CASE( "map_test_case_transform_consistency", "[map_test_case]" )
{
    using namespace map_test_case_common;
    using mtc = map_test_case;

    mtc tst;
    tst.anchor_char = '5';
    tst.setup = {
        "123",
        "456",
        "789",
    };
    tst.expected_results = {
        "123",
        "456",
        "789",
    };

    SECTION( tst.generate_transform_combinations() ) {
    }

    // assumes tst.anchor_map_pos == tripoint_zero
    CHECK( tst.get_origin() == tripoint_north_west );
    tst.validate_anchor_point( tripoint_zero );

    std::set<tripoint> tiles;
    tst.for_each_tile( [&]( mtc::tile t ) {
        tiles.emplace( t.p );
    } );

    CHECK( tiles.size() == 9 );

    std::vector<tripoint> neigh_vec(
        std::begin( eight_horizontal_neighbors ),
        std::end( eight_horizontal_neighbors )
    );
    neigh_vec.push_back( tripoint_zero );
    CHECK_THAT( std::vector<tripoint>( tiles.begin(), tiles.end() ),
                Catch::UnorderedEquals( neigh_vec ) );

    tst.for_each_tile( [&]( mtc::tile t ) {
        CHECK( t.expect_c == t.setup_c );
        CHECK( tiles.count( t.p ) == 1 );
    } );
}

// checks transformations for non-square field
TEST_CASE( "map_test_case_transform_non_square", "[map_test_case]" )
{
    using namespace map_test_case_common;
    using mtc = map_test_case;

    mtc tst;
    tst.anchor_char = '1';
    tst.setup = {
        "12345"
    };
    tst.expected_results = {
        "abcde"
    };

    SECTION( tst.generate_transform_combinations() ) {
    }
    tst.validate_anchor_point( tripoint_zero );

    CAPTURE( tst.get_width(), tst.get_height() );
    CHECK(
        ( ( tst.get_width() == 5 && tst.get_height() == 1 ) ||
          ( tst.get_width() == 1 && tst.get_height() == 5 ) )
    );

    CAPTURE( tst.get_origin() );
    CHECK( std::set<tripoint> {
        tripoint_zero, {-4, 0, 0}, {0, -4, 0}
    } .count( tst.get_origin() ) );

    tst.for_each_tile( [&]( mtc::tile t ) {
        CHECK( t.expect_c - 'a' == t.setup_c - '1' );
    } );
}