File: speed_description_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 (104 lines) | stat: -rw-r--r-- 3,925 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
#include "catch/catch.hpp"
#include "monster.h"
#include "mtype.h"
#include "player_helpers.h"
#include "speed_description.h"

#include <algorithm>

static const mtype_id mon_test_speed_desc_base( "mon_test_speed_desc_base" );
static const mtype_id mon_test_speed_desc_base_150( "mon_test_speed_desc_base_150" );
static const mtype_id mon_test_speed_desc_base_25( "mon_test_speed_desc_base_25" );
static const mtype_id mon_test_speed_desc_base_50( "mon_test_speed_desc_base_50" );
static const mtype_id mon_test_speed_desc_base_immobile( "mon_test_speed_desc_base_immobile" );
static const mtype_id mon_test_speed_desc_multiple( "mon_test_speed_desc_multiple" );

static const speed_description_id
speed_description_ID_THAT_DOES_NOT_EXIST( "ID_THAT_DOES_NOT_EXIST" );

TEST_CASE( "monster_speed_description", "[monster][speed_description]" )
{
    /*
     * A default character has a speed of 100 and a base move cost of 116
     * That means their tiles per turn is 100 / 116 == 0.86206896551
     * The tiles per turn ratio is monster_ratio / player_ratio
     */

    auto get_speed_string = []( const mtype_id & mon_id ) {
        clear_avatar();
        monster mon( mon_id );
        return monster::speed_description(
                   mon.speed_rating(),
                   mon.has_flag( mon_flag_IMMOBILE ),
                   mon.type->speed_desc
               );
    };

    // while lambdas speed things up, in-case the check fails
    // they don't give the line where the check failed
    // so give the contributor as much info as possible when describing the cases
    auto make_test = [&get_speed_string]( const mtype_id & mon_id,
    const std::vector<std::string> &descriptions ) {
        std::string speed_string = get_speed_string( mon_id );
        THEN( "returned string is the one expected" ) {
            const bool is_returned_string_is_inside_vector = std::find(
                        descriptions.begin(), descriptions.end(),
                        speed_string ) != descriptions.end();
            // variable name will show up when error fails
            CHECK( is_returned_string_is_inside_vector );
        }
    };

    SECTION( "passing invalid parameters" ) {
        GIVEN( "a null id" ) {
            std::string speed_string =
                monster::speed_description( 1.0, false, speed_description_id::NULL_ID() );

            THEN( "returned string is empty" ) {
                CHECK( speed_string.empty() );
            }
        }

        GIVEN( "an invalid id" ) {
            std::string speed_string =
                monster::speed_description( 1.0, false,
                                            speed_description_ID_THAT_DOES_NOT_EXIST );

            THEN( "returned string is empty" ) {
                CHECK( speed_string.empty() );
            }
        }
    }

    SECTION( "monster with valid speed description" ) {
        GIVEN( "immobile monster" ) {
            make_test( mon_test_speed_desc_base_immobile, {"Monster immobile"} );
        }

        GIVEN( "monster with 25 speed" ) {
            make_test( mon_test_speed_desc_base_25, {"Monster speed 25"} );
        }

        GIVEN( "monster with 50 speed" ) {
            make_test( mon_test_speed_desc_base_50, {"Monster speed 50"} );
        }

        GIVEN( "monster with 100 speed" ) {
            make_test( mon_test_speed_desc_base, {"Monster speed 100"} );
        }

        GIVEN( "monster with 150 speed" ) {
            make_test( mon_test_speed_desc_base_150, {"Monster speed 150"} );
        }
    }

    SECTION( "monster with multiple speed description values" ) {
        GIVEN( "monster with 100 speed and multiple speed descriptions" ) {
            make_test( mon_test_speed_desc_multiple, {
                "A Monster speed description A",
                "B Monster speed description B",
                "C Monster speed description C"
            } );
        }
    }
}