Skip to content

Commit d9ca328

Browse files
Replace GoldManager with mock in all tests
- Removing GoldManager dependency in all tests and adding GoldManagerMock
1 parent 1ccffdd commit d9ca328

File tree

19 files changed

+81
-76
lines changed

19 files changed

+81
-76
lines changed

src/main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "state/actor/soldier.h"
1111
#include "state/actor/villager.h"
1212
#include "state/command_giver.h"
13+
#include "state/gold_manager/gold_manager.h"
1314
#include "state/map/map.h"
1415
#include "state/path_planner/path_planner.h"
1516
#include "state/player_state.h"

src/state/include/state/actor/actor.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#pragma once
77

88
#include "physics/vector.hpp"
9-
#include "state/gold_manager/gold_manager.h"
9+
#include "state/interfaces/i_gold_manager.h"
1010
#include "state/interfaces/i_updatable.h"
1111
#include "state/state_export.h"
1212
#include "state/utilities.h"
@@ -18,7 +18,10 @@ namespace state {
1818
* Actor base class
1919
*/
2020

21-
class GoldManager;
21+
/**
22+
* Forward declaration of IGoldManager
23+
*/
24+
class IGoldManager;
2225

2326
class STATE_EXPORT Actor : public IUpdatable {
2427
protected:
@@ -61,13 +64,13 @@ class STATE_EXPORT Actor : public IUpdatable {
6164
/**
6265
* Gold manager instance to perform transactions
6366
*/
64-
GoldManager *gold_manager;
67+
IGoldManager *gold_manager;
6568

6669
public:
6770
Actor();
6871

6972
Actor(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
70-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager);
73+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager);
7174

7275
virtual ~Actor() {}
7376

@@ -121,7 +124,7 @@ class STATE_EXPORT Actor : public IUpdatable {
121124
*
122125
* @return gold_manager Unit's GoldManager Pointer
123126
*/
124-
GoldManager *GetGoldManager();
127+
IGoldManager *GetGoldManager();
125128

126129
/**
127130
* Get the maximum hp of the actor

src/state/include/state/actor/factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class STATE_EXPORT Factory : public Actor {
7979
Factory();
8080

8181
Factory(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
82-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
82+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
8383
int64_t construction_complete, int64_t construction_total,
8484
ActorType production_state, int64_t villager_frequency,
8585
int64_t soldier_frequency,

src/state/include/state/actor/soldier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class STATE_EXPORT Soldier : public Unit {
2929
Soldier();
3030

3131
Soldier(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
32-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
32+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
3333
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
3434
int64_t attack_damage);
3535

src/state/include/state/actor/unit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class STATE_EXPORT Unit : public Actor {
7979
Unit();
8080

8181
Unit(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
82-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
82+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
8383
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
8484
int64_t attack_damage);
8585

src/state/include/state/actor/villager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "state/actor/factory.fwd.h"
1010
#include "state/actor/unit.h"
1111
#include "state/actor/villager_states/villager_state.h"
12-
#include "state/gold_manager/gold_manager.h"
1312

1413
namespace state {
1514

@@ -62,7 +61,7 @@ class STATE_EXPORT Villager : public Unit {
6261
Villager();
6362

6463
Villager(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
65-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
64+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
6665
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
6766
int64_t attack_damage, int64_t build_effort, int64_t build_range,
6867
int64_t mine_range);

src/state/include/state/state.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "state/actor/factory.h"
1111
#include "state/actor/soldier.h"
1212
#include "state/actor/villager.h"
13-
#include "state/gold_manager/gold_manager.h"
1413
#include "state/interfaces/i_command_taker.h"
14+
#include "state/interfaces/i_gold_manager.h"
1515
#include "state/interfaces/i_updatable.h"
1616
#include "state/map/map.h"
1717
#include "state/path_planner/path_planner.h"
@@ -33,7 +33,7 @@ class STATE_EXPORT State : public ICommandTaker {
3333
/**
3434
* Gold Manager instance to maintain player gold
3535
*/
36-
std::unique_ptr<GoldManager> gold_manager;
36+
std::unique_ptr<IGoldManager> gold_manager;
3737

3838
/**
3939
* Path Planner instance
@@ -119,7 +119,7 @@ class STATE_EXPORT State : public ICommandTaker {
119119
/**
120120
* Constructor
121121
*/
122-
State(std::unique_ptr<Map> map, std::unique_ptr<GoldManager> gold_manager,
122+
State(std::unique_ptr<Map> map, std::unique_ptr<IGoldManager> gold_manager,
123123
std::unique_ptr<PathPlanner> path_planner,
124124
std::array<std::vector<std::unique_ptr<Soldier>>, 2> soldiers,
125125
std::array<std::vector<std::unique_ptr<Villager>>, 2> villagers,

src/state/src/actor/actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Actor::Actor() {
1414
}
1515

1616
Actor::Actor(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
17-
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager)
17+
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager)
1818
: id(id), player_id(player_id), actor_type(actor_type), hp(hp),
1919
max_hp(max_hp), position(position), gold_manager(gold_manager) {}
2020

@@ -34,7 +34,7 @@ PlayerId Actor::GetPlayerId() { return player_id; }
3434

3535
ActorType Actor::GetActorType() { return actor_type; }
3636

37-
GoldManager *Actor::GetGoldManager() { return gold_manager; }
37+
IGoldManager *Actor::GetGoldManager() { return gold_manager; }
3838

3939
int64_t Actor::GetHp() { return hp; }
4040

src/state/src/actor/factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Factory::Factory() {}
1414

1515
Factory::Factory(ActorId id, PlayerId player_id, ActorType actor_type,
1616
int64_t hp, int64_t max_hp, DoubleVec2D position,
17-
GoldManager *gold_manager, int64_t construction_complete,
17+
IGoldManager *gold_manager, int64_t construction_complete,
1818
int64_t construction_total, ActorType production_state,
1919
int64_t villager_frequency, int64_t soldier_frequency,
2020
UnitProductionCallback unit_production_callback)

src/state/src/actor/soldier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Soldier::Soldier() {
1616
}
1717
Soldier::Soldier(ActorId id, PlayerId player_id, ActorType actor_type,
1818
int64_t hp, int64_t max_hp, DoubleVec2D position,
19-
GoldManager *gold_manager, PathPlanner *path_planner,
19+
IGoldManager *gold_manager, PathPlanner *path_planner,
2020
int64_t speed, int64_t attack_range, int64_t attack_damage)
2121
: Unit(id, player_id, actor_type, hp, max_hp, position, gold_manager,
2222
path_planner, speed, attack_range, attack_damage),

0 commit comments

Comments
 (0)