Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score feature by TDD example #2

Merged
merged 10 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/TDD/Score.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "Score.hpp"

Score::Score(int value)
{
this->value = value;
};

Score Score::sum(int value)
{
return Score(this->value + value);
};

Score Score::subtract(int value)
{
return Score(this->value - value);
};

bool Score::equal(const Score& s) const
{
return this->value == s.value;
}
19 changes: 19 additions & 0 deletions src/TDD/Score.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef Score_hpp
#define Score_hpp

class Score
{
private:
int value = 0;
public:
Score(int value);
Score sum(int value);
Score subtract(int value);
bool equal(const Score& s) const;
bool operator==(const Score& s) const
{
return equal(s);
};
};

#endif /* Score_hpp */
24 changes: 24 additions & 0 deletions tests/TDD/testScore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "../catch.hpp"
#include "../../src/TDD/Score.cpp"

TEST_CASE("Score") {
SECTION("test sum") {
Score score(10);
Score newScore = score.sum(45);
Score toCompare(55);
CHECK(newScore == toCompare);
}

SECTION("test equality") {
Score score(10);
Score toCompare(10);
CHECK(score.equal(toCompare));
}

SECTION("test subtract") {
Score score(100);
Score newScore = score.subtract(45);
Score toCompare(55);
CHECK(newScore == toCompare);
}
}