Skip to content

Commit 3b2b1ed

Browse files
Kyle GrageKyle Grage
authored andcommitted
Starting tests, upgrade to == operator, fixed bug where wonder was not
inherited from cp
1 parent 18f26b8 commit 3b2b1ed

File tree

8 files changed

+138
-2
lines changed

8 files changed

+138
-2
lines changed

include/City.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class City : public CornerPiece {
2121

2222
int getResourceModifier();
2323
int getVictoryPoints();
24+
25+
bool operator==(const City&) const;
2426
};
2527

2628
#endif

include/CornerPiece.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class CornerPiece : public GamePiece {
2323
virtual int getResourceModifier();
2424

2525
virtual int getVictoryPoints();
26+
27+
virtual bool operator==(const CornerPiece&) const;
2628
};
2729

2830
#endif

include/Settlement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Settlement : public CornerPiece {
2020
virtual bool operator==(const GamePiece&) const;
2121
int getResourceModifier();
2222
int getVictoryPoints();
23+
24+
bool operator==(const Settlement&) const;
2325
};
2426

2527
#endif

include/Wonder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "CornerPiece.h"
1212

13-
class Wonder {
13+
class Wonder : public CornerPiece {
1414
private:
1515

1616
public:
@@ -25,6 +25,8 @@ class Wonder {
2525

2626
int getResourceModifier();
2727
int getVictoryPoints();
28+
29+
bool operator==(const Wonder&) const;
2830
};
2931

3032
#endif /* WONDER_H_ */

src/City.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,16 @@ int City::getVictoryPoints() {
5858
City::City(CornerPiece& sett) : CornerPiece(sett.getBoard(), sett.getLocation(), sett.getOwner()) {
5959

6060
}
61+
62+
/**
63+
* Determines if a piece is the same
64+
* @return boolean
65+
*/
66+
bool City::operator==(const City& other) const {
67+
auto city = dynamic_cast<const City*>(&other);
68+
if(city) {
69+
return getOwner().getName() == city->getOwner().getName() && getLocation() == city->getLocation();
70+
} else {
71+
return false;
72+
}
73+
}

src/CornerPiece.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ int CornerPiece::getVictoryPoints() {
4747
*/
4848
int CornerPiece::getResourceModifier() {
4949
return 0;
50-
}
50+
}
51+
52+
/**
53+
* Determines if a piece is the same
54+
* @return boolean
55+
*/
56+
bool CornerPiece::operator==(const CornerPiece& other) const {
57+
auto cp = dynamic_cast<const CornerPiece*>(&other);
58+
if(cp) {
59+
return getOwner().getName() == cp->getOwner().getName() && getLocation() == cp->getLocation();
60+
} else {
61+
return false;
62+
}
63+
}

src/Wonder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ Wonder::Wonder(CornerPiece& sett) : CornerPiece(sett.getBoard(), sett.getLocatio
6969

7070
}
7171

72+
/**
73+
* Determines if a piece is the same
74+
* @return boolean
75+
*/
76+
bool City::operator==(const City& other) const {
77+
auto won = dynamic_cast<const Wonder*>(&other);
78+
if(won) {
79+
return getOwner().getName() == won->getOwner().getName() && getLocation() == won->getLocation();
80+
} else {
81+
return false;
82+
}
83+
}
84+

tests/test_cornerpiece.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* test_cornerpiece.cpp
3+
*
4+
* Created on: Apr 10, 2014
5+
* Author: Kyle Grage
6+
*/
7+
8+
#include "UnitTest++.h"
9+
#include "CornerPiece.h"
10+
#include "Settlement.h"
11+
#include "City.h"
12+
#include "Wonder.h"
13+
14+
//TEST CONSTRUCTORS
15+
TEST(CornerPiece_constructor){
16+
Coordinate loc = Coordinate(0,0);
17+
GameBoard board({"test board"});
18+
Player& test_player = board.getPlayer(0);
19+
20+
CornerPiece test_cp(&board, loc, test_player);
21+
}
22+
23+
TEST(Settlement_constructor){
24+
Coordinate loc = Coordinate(0,0);
25+
GameBoard board({"test board"});
26+
Player& test_player = board.getPlayer(0);
27+
28+
Settlement test_cp(&board, loc, test_player);
29+
}
30+
31+
TEST(City_constructor){
32+
Coordinate loc = Coordinate(0,0);
33+
GameBoard board({"test board"});
34+
Player& test_player = board.getPlayer(0);
35+
36+
City test_cp(&board, loc, test_player);
37+
}
38+
39+
TEST(Wonder_constructor){
40+
Coordinate loc = Coordinate(0,0);
41+
GameBoard board({"test board"});
42+
Player& test_player = board.getPlayer(0);
43+
44+
Wonder test_cp(&board, loc, test_player);
45+
}
46+
47+
TEST(City_upgrade_constructor){
48+
49+
}
50+
51+
TEST(Wonder_upgrade_constructor){
52+
53+
}
54+
55+
//TEST RESOURCE MODIFIERS
56+
TEST(CornerPiece_Resource_Mod){
57+
58+
}
59+
60+
TEST(Settlement_Resource_Mod){
61+
62+
}
63+
64+
TEST(City_Resource_Mod){
65+
66+
}
67+
68+
TEST(Wonder_Resource_Mod){
69+
70+
}
71+
72+
//TEST VICTORY POINTS
73+
TEST(CornerPiece_Victory_Pts){
74+
75+
}
76+
77+
TEST(Settlement_Victory_Pts){
78+
79+
}
80+
81+
TEST(City_Victory_Pts){
82+
83+
}
84+
85+
TEST(Wonder_Victory_Pts){
86+
87+
}
88+
89+

0 commit comments

Comments
 (0)