Skip to content

Commit 86b3bef

Browse files
committed
Editing tests back to google test for sanity's sake
1 parent cdfa123 commit 86b3bef

16 files changed

+324
-453
lines changed

include/GameController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ class GameController {
3939
bool handleRoadButtonEvent(ScreenCoordinate);
4040
bool handleSettlementButtonEvent(ScreenCoordinate);
4141
bool handleRoadCardButtonEvent(ScreenCoordinate);
42+
43+
bool handleBuyDevelopmentCardButtonEvent(ScreenCoordinate);
4244
bool handleKnightCardButtonEvent(ScreenCoordinate);
4345
bool handleYearOfPlentyCardButtonEvent(ScreenCoordinate);
4446
bool handleMonopolyCardButtonEvent(ScreenCoordinate);
4547
bool handleVictoryPointCardButtonEvent(ScreenCoordinate);
48+
4649
bool handleCancelButtonEvent(ScreenCoordinate);
4750

4851
bool handleConfirmRoadCard(ScreenCoordinate);

include/GameView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class GameView {
5353

5454
void highlightPoint(ScreenCoordinate & coord);
5555
void drawCardCount(std::string font, int fontSize);
56+
void drawResourceCount(std::string font, int fontSize);
5657

5758
GameView(const GameView& o) = delete;
5859
GameView& operator=(const GameView& o) = delete;
@@ -69,6 +70,7 @@ class GameView {
6970
void addElement(std::unique_ptr<ViewElement> element);
7071
void addElement(int priority, std::unique_ptr<ViewElement>);
7172

73+
7274
std::unique_ptr<ViewElement> removeElement(int priority);
7375
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
7476
std::unique_ptr<ViewElement> removeElement(const ViewElement&);

src/GameBoard.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
409409
const Coordinate& diff = adjacentCoordDiffs[i];
410410
Coordinate adjacentPoint(location.first + diff.first,
411411
location.second + diff.second);
412-
auto it = resources.find(adjacentPoint);
413-
if (it != resources.end()) {
412+
auto it = corners.find(adjacentPoint);
413+
if (it != corners.end()) {
414414
GamePiece* piece = it->second.get();
415415
if (dynamic_cast<CornerPiece*>(piece)) {
416416
v.push_back(static_cast<CornerPiece*>(piece));
@@ -421,6 +421,7 @@ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
421421
}
422422

423423

424+
424425
/**
425426
* Checks to make sure the coordinate is within bounds of the board and not a resource tile.
426427
* @param coord The coordinate to check.

src/GameController.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3737

3838
view.addElement(makeViewButtonColor(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.95, .95}, {1.0, 1.0}}, std::make_tuple(1.f, 0.0f, 0.f)));
3939

40+
view.addElement(makeViewButtonText(std::bind(&GameController::handleBuyDevelopmentCardButtonEvent, this, _1), {{.85, .23}, {1, .30}}, font, fontSize, "Development Cards"));
4041
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
4142
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
4243
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));
@@ -283,6 +284,11 @@ bool GameController::handleCancelDialogueEvent(ScreenCoordinate coord){
283284
return handleCancelButtonEvent(coord);
284285
}
285286

287+
bool GameController::handleBuyDevelopmentCardButtonEvent(ScreenCoordinate coord){
288+
model.buyCard(model.getCurrentPlayer());
289+
return handleCancelButtonEvent(coord);
290+
}
291+
286292
/**
287293
* Handles a click on the Knight Card button.
288294
* @param coord The place the user clicked

src/GameView.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ GameView::~GameView() {
104104
* @return void
105105
*/
106106
void GameView::drawCardCount(std::string font, int fontSize){
107-
108-
renderText(font, fontSize, {.85, .23}, {1, .30}, "Development Cards");
109-
110107
renderText(font, fontSize, {0.97, 0.0}, {1.0, 0.05},
111108
toString(model.getCurrentPlayer().getRoadBuildingCards())); //Road Building
112109
renderText(font, fontSize, {0.97, 0.05}, {1.0, 0.1},
@@ -119,6 +116,20 @@ void GameView::drawCardCount(std::string font, int fontSize){
119116
toString(model.getCurrentPlayer().getVictoryCards())); //Victory Point
120117
}
121118

119+
void GameView::drawResourceCount(std::string font, int fontSize){
120+
renderText(font, fontSize, {0.97, 0.35}, {1.0, 0.40},
121+
toString(model.getCurrentPlayer().getWood())); //Wood
122+
renderText(font, fontSize, {0.97, 0.40}, {1.0, 0.45},
123+
toString(model.getCurrentPlayer().getWool())); //Sheep
124+
renderText(font, fontSize, {0.97, 0.45}, {1.0, 0.50},
125+
toString(model.getCurrentPlayer().getOre())); //Ore
126+
renderText(font, fontSize, {0.97, 0.50}, {1.0, 0.55},
127+
toString(model.getCurrentPlayer().getBrick())); //Brick
128+
renderText(font, fontSize, {0.97, 0.55}, {1.0, 0.60},
129+
toString(model.getCurrentPlayer().getWheat())); //Wheat
130+
131+
}
132+
122133

123134
/**
124135
* Display the GameBoard to the screen as well as additional ViewElements.
@@ -143,6 +154,7 @@ void GameView::render() {
143154
renderText(font, fontSize, {.2, .9}, {.8, 1}, "Settlers of Catan");
144155

145156
drawCardCount(font, fontSize);
157+
drawResourceCount(font, fontSize);
146158

147159
glFlush();
148160
}

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ run: $(TEST_FILE)
88
./$(TEST_FILE)
99

1010
$(TEST_FILE): ../$(EXECUTABLE) $(TEST_LINK_FILES) $(wildcard *.cpp)
11-
$(CXX) $(CXXFLAGS) -I$(TEST_INCLUDE) $(wildcard *.cpp) -o $@ $(TEST_LINK_FILES) $(OBJECTS_NO_MAIN) $(LDFLAGS)
11+
$(CXX) $(CXXFLAGS) $(TEST_INCLUDE) $(wildcard *.cpp) -o $@ $(TEST_LINK_FILES) $(OBJECTS_NO_MAIN) $(LDFLAGS)
1212

1313
.PHONY: clean
1414
clean:

tests/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#include <UnitTest++.h>
1+
#include "gtest/gtest.h"
22

3-
int main() {
4-
return UnitTest::RunAllTests();
3+
int main(int argc, char** argv) {
4+
::testing::InitGoogleTest(&argc, argv);
5+
6+
return RUN_ALL_TESTS();
57
}
68

tests/testConfig.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
#include "UnitTest++.h"
1+
#include <stdexcept>
2+
3+
#include "gtest/gtest.h"
4+
25
#include "Config.h"
36

4-
#include <stdexcept>
57

68
using std::string;
79
using std::stringstream;
810

9-
TEST(readOneString) {
11+
TEST(ConfigTest, readOneString) {
1012
stringstream file("variable=value");
1113
Config config(file);
1214

13-
CHECK((string)config["variable"] == "value");
15+
ASSERT_EQ((string)config["variable"], "value");
1416
}
1517

16-
TEST(readTwoStrings) {
18+
TEST(ConfigTest, readTwoStrings) {
1719
stringstream file("var_a=val_a\nvar_b=val_b\n");
1820
Config config(file);
1921

20-
CHECK((string)config["var_a"] == "val_a");
21-
CHECK((string)config["var_b"] == "val_b");
22+
ASSERT_EQ((string)config["var_a"], "val_a");
23+
ASSERT_EQ((string)config["var_b"], "val_b");
2224
}
2325

24-
TEST(readFloat) {
26+
TEST(ConfigTest, readFloat) {
2527
stringstream file("float=5.0\n");
2628
Config config(file);
2729

28-
CHECK((float)config["float"] == 5.0f);
30+
ASSERT_EQ((float)config["float"], 5.0f);
2931
}
3032

31-
TEST(readCommentsEmptyLines) {
33+
TEST(ConfigTest, readCommentsEmptyLines) {
3234
stringstream file("#this is a string\nstring=hello\n#we just had a string\n\n\n\n\n");
3335
Config config(file);
3436

35-
CHECK((string)config["string"] == "hello");
37+
ASSERT_EQ((string)config["string"], "hello");
3638
}
3739

38-
TEST(readInvalid) {
40+
TEST(ConfigTest, readInvalid) {
3941
stringstream file("variable=value");
4042
Config config(file);
4143

42-
CHECK_THROW((string)config["string"] == "hello", std::runtime_error);
44+
ASSERT_THROW((string)config["string"] == "hello", std::runtime_error);
4345
}
4446

45-
TEST(readCoordinate) {
47+
TEST(ConfigTest, readCoordinate) {
4648
stringstream file("coord=(1,2)");
4749
Config config(file);
4850

49-
CHECK(Coordinate({1, 2}) == (Coordinate)config["coord"]);
51+
ASSERT_EQ(Coordinate({1, 2}), (Coordinate)config["coord"]);
5052
}
5153

52-
TEST(readScreenCoordinate) {
54+
TEST(ConfigTest, readScreenCoordinate) {
5355
stringstream file("coord=(1.5,2.5)");
5456
Config config(file);
5557

56-
CHECK(ScreenCoordinate({1.5, 2.5}) == (ScreenCoordinate)config["coord"]);
58+
ASSERT_EQ(ScreenCoordinate({1.5, 2.5}), (ScreenCoordinate)config["coord"]);
5759
}

tests/testRenderer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#include <iostream>
22

3-
#include "UnitTest++.h"
3+
#include "gtest/gtest.h"
4+
45
#include "Renderer.h"
56

67
using std::make_pair;
78

8-
TEST(coordToScreen) {
9+
TEST(RendererTest, coordToScreen) {
910
for(int x = -5; x < 5; x++) {
1011
for(auto y = -5; y < 5; y++) {
1112
auto original = make_pair(x, y);
1213
auto screen = coordToScreen(original);
1314
auto back = screenToCoord(screen);
14-
CHECK(original.first == back.first);
15-
CHECK(original.second == back.second);
15+
ASSERT_EQ(original.first, back.first);
16+
ASSERT_EQ(original.second, back.second);
1617
}
1718
}
1819
}

tests/testSerialization.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#include <UnitTest++.h>
1+
#include <iostream>
2+
#include <sstream>
3+
#include <memory>
4+
#include <vector>
5+
6+
#include "gtest/gtest.h"
27

38
#include "Serialization.h"
49
#include "GameBoard.h"
@@ -7,37 +12,31 @@
712

813
#include "tinyxml2.h"
914

10-
#include <iostream>
11-
#include <sstream>
12-
#include <memory>
13-
#include <vector>
14-
1515
using std::vector;
1616
using std::unique_ptr;
1717
using std::stringstream;
1818

19-
TEST(emptyBoardSerialization) {
19+
TEST(SerializationTest, emptyBoardSerialization) {
2020
GameBoard testBoard({});
2121

2222
stringstream stream;
2323
testBoard.save(stream);
2424

2525
GameBoard copyBoard(stream);
26-
27-
CHECK(testBoard == copyBoard);
26+
ASSERT_EQ(testBoard, copyBoard);
2827
}
2928

30-
TEST(multiplePlayerSerialization) {
29+
TEST(SerializationTest, multiplePlayerSerialization) {
3130
GameBoard testBoard({"test", "test2"});
3231
stringstream stream;
3332
testBoard.save(stream);
3433

3534
GameBoard copyBoard(stream);
36-
37-
CHECK(testBoard == copyBoard);
35+
36+
ASSERT_EQ(testBoard, copyBoard);
3837
}
3938

40-
TEST(testCardSerialization) {
39+
TEST(SerializationTest, testCardSerialization) {
4140
GameBoard testBoard({"test"});
4241
Player& testPlayer = testBoard.getPlayer(0);
4342

@@ -58,11 +57,10 @@ TEST(testCardSerialization) {
5857
testBoard.save(stream);
5958

6059
GameBoard copyBoard(stream);
61-
62-
CHECK(testBoard == copyBoard);
60+
ASSERT_EQ(testBoard, copyBoard);
6361
}
6462

65-
TEST(roadSerialization) {
63+
TEST(SerializationTest, roadSerialization) {
6664
GameBoard testBoard({"test", "test2"});
6765
Player& firstPlayer = testBoard.getPlayer(0);
6866
Player& secondPlayer = testBoard.getPlayer(1);
@@ -76,11 +74,10 @@ TEST(roadSerialization) {
7674
testBoard.save(stream);
7775

7876
GameBoard copyBoard(stream);
79-
80-
CHECK(testBoard == copyBoard);
77+
ASSERT_EQ(testBoard, copyBoard);
8178
}
8279

83-
TEST(settlementSerialization) {
80+
TEST(SerializationTest, settlementSerialization) {
8481
GameBoard testBoard({"test"});
8582
Player& player = testBoard.getPlayer(0);
8683

@@ -91,6 +88,5 @@ TEST(settlementSerialization) {
9188
testBoard.save(stream);
9289

9390
GameBoard copyBoard(stream);
94-
95-
CHECK(testBoard == copyBoard);
91+
ASSERT_EQ(testBoard, copyBoard);
9692
}

0 commit comments

Comments
 (0)