-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathbionics_test.cpp
99 lines (81 loc) · 3 KB
/
bionics_test.cpp
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
#include "catch/catch.hpp"
#include <climits>
#include <list>
#include <memory>
#include <string>
#include "avatar.h"
#include "bionics.h"
#include "calendar.h"
#include "item.h"
#include "pimpl.h"
#include "player.h"
#include "player_helpers.h"
#include "state_helpers.h"
#include "type_id.h"
#include "units.h"
static void clear_bionics( player &p )
{
p.my_bionics->clear();
p.set_power_level( 0_kJ );
p.set_max_power_level( 0_kJ );
}
static void test_consumable_charges( player &p, std::string &itemname, bool when_none,
bool when_max )
{
item &it = *item::spawn_temporary( itemname, calendar::start_of_cataclysm, 0 );
INFO( "\'" + it.tname() + "\' is count-by-charges" );
CHECK( it.count_by_charges() );
it.charges = 0;
INFO( "consume \'" + it.tname() + "\' with " + std::to_string( it.charges ) + " charges" );
REQUIRE( p.can_consume( it ) == when_none );
it.charges = INT_MAX;
INFO( "consume \'" + it.tname() + "\' with " + std::to_string( it.charges ) + " charges" );
REQUIRE( p.can_consume( it ) == when_max );
}
static void test_consumable_ammo( player &p, std::string &itemname, bool when_empty,
bool when_full )
{
detached_ptr<item> it = item::spawn( itemname, calendar::start_of_cataclysm, 0 );
it->ammo_unset();
INFO( "consume \'" + it->tname() + "\' with " + std::to_string( it->ammo_remaining() ) +
" charges" );
REQUIRE( p.can_consume( *it ) == when_empty );
it->ammo_set( it->ammo_default(), -1 ); // -1 -> full
INFO( "consume \'" + it->tname() + "\' with " + std::to_string( it->ammo_remaining() ) +
" charges" );
REQUIRE( p.can_consume( *it ) == when_full );
}
TEST_CASE( "bionics", "[bionics] [item]" )
{
clear_all_state();
avatar &dummy = get_avatar();
// one section failing shouldn't affect the rest
clear_bionics( dummy );
// Could be a SECTION, but prerequisite for many tests.
INFO( "no power capacity at first" );
CHECK( !dummy.has_max_power() );
dummy.add_bionic( bionic_id( "bio_power_storage" ) );
INFO( "adding Power Storage CBM only increases capacity" );
CHECK( !dummy.has_power() );
REQUIRE( dummy.has_max_power() );
SECTION( "bio_batteries" ) {
give_and_activate_bionic( dummy, bionic_id( "bio_batteries" ) );
static const std::list<std::string> always = {
"battery" // old-school
};
for( auto it : always ) {
test_consumable_charges( dummy, it, true, true );
}
static const std::list<std::string> never = {
"flashlight", // !is_magazine()
"laser_rifle", // NO_UNLOAD, uses ups_charges
"UPS_off", // NO_UNLOAD, !is_magazine()
"battery_car" // NO_UNLOAD, is_magazine()
};
for( auto it : never ) {
test_consumable_ammo( dummy, it, false, false );
}
}
// TODO: bio_cable bio_reactor
// TODO: (pick from stuff with power_source)
}