Commits

trikitrok committed a031931 Draft

Added new Player class. Not integrated with Game yet

Comments (0)

Files changed (3)

+#include "Player.h"
+
+Player::Player(const std::string & name)
+{
+	this->name = name;
+	this->points = 0;
+}
+
+Player::~Player()
+{}
+
+int Player::getPoints() const
+{
+	return this->points;
+}
+
+void Player::winPoint()
+{
+	this->points++;
+}
+
+std::string Player::getName() const
+{
+	return this->name;
+}
+
+bool Player::wonMoreThanThreePoints() const
+{
+	return this->points > 3;
+}
+#ifndef PLAYER_H_
+#define PLAYER_H_
+
+#include <string>
+
+class Player
+{
+	public:
+		Player(const std::string & name);
+		virtual ~Player();
+
+		int getPoints() const;
+		void winPoint();
+
+		std::string getName() const;
+
+		bool wonMoreThanThreePoints() const;
+
+	private:
+		int points;
+		std::string name;
+};
+
+#endif /* PLAYER_H_ */

src/test/PlayerTests.cpp

+#include <CppUTest/TestHarness.h>
+
+#include "../Player.h"
+
+TEST_GROUP(PlayerTests)
+{
+	Player * player;
+
+	void setup() {
+		player = new Player("koko");
+	}
+
+	void teardown() {
+		delete player;
+	}
+
+};
+
+TEST(PlayerTests, playerHasZeroPointsAfterBeingCreated)
+{
+	LONGS_EQUAL(0, player->getPoints());
+}
+
+TEST(PlayerTests, playerHasNameAfterBeingCreated)
+{
+	CHECK("koko" == player->getName());
+}
+
+TEST(PlayerTests, playerWinPoints)
+{
+	player->winPoint();
+	LONGS_EQUAL(1, player->getPoints());
+
+	player->winPoint();
+	LONGS_EQUAL(2, player->getPoints());
+}
+
+TEST(PlayerTests, playerHasWonMoreThanThreePoints)
+{
+	player->winPoint();
+	player->winPoint();
+
+	CHECK(not player->wonMoreThanThreePoints());
+
+	player->winPoint();
+
+	CHECK(not player->wonMoreThanThreePoints());
+
+	player->winPoint();
+
+	CHECK(player->wonMoreThanThreePoints());
+}
+
+
+
+