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

[US.1][4] Object representation of cards #12 #13

Open
wants to merge 63 commits into
base: master
Choose a base branch
from

Conversation

Angan7a
Copy link
Collaborator

@Angan7a Angan7a commented Oct 12, 2018

fix #12

src/Card.hpp Outdated
{
std::array<std::string, 16> jobs_;
public:
void setJob(int number, const std::string & job);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Angan7a I think the number can be const


TEST_F(CardTests, check_if_call_setJob_out_of_range_will_throw_exception)
{
ASSERT_THROW(redCard.setJob(-9, "Cofasz się o trzy pola." ), std::exception);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't care about the exception type we can use ASSERT_ANY_THROW. If we care then probably std::out_of_range is a proper exception type :)


TEST_F(CardTests, set_job_3_Wracasz_do_Madrytu_check_if_value_getJob_3_return_the_same_message)
{
redCard.setJob(3, "Wracasz do Madrytu.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract a string to a variable and use it here and in ASSERT_EQ

src/Card.hpp Outdated
#include <string>
#include <array>

class Card
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Card color?

src/Card.hpp Outdated

class Card
{
std::array<std::string, 16> jobs_;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I get a concept of this representation. We will have an array with cards descriptions, which are set by a setter. Why not in a constructor? Who (which class) will set those values?

@codecov
Copy link

codecov bot commented Oct 16, 2018

Codecov Report

Merging #13 into master will increase coverage by 1.63%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #13      +/-   ##
==========================================
+ Coverage    93.1%   94.73%   +1.63%     
==========================================
  Files           6        8       +2     
  Lines          29       38       +9     
==========================================
+ Hits           27       36       +9     
  Misses          2        2
Impacted Files Coverage Δ
src/Cards.hpp 100% <100%> (ø)
src/Cards.cpp 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0d72da...4e31459. Read the comment docs.


struct CardsTests : public ::testing::Test
{
json dataJson = R"({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to keep this info in a separate json file and read it in this test file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need only 1 card for test this class, so I make it in class CardsTests - than test will be independent of the size of input json file ;-).

src/Cards.cpp Outdated
@@ -0,0 +1,18 @@
#include "Cards.hpp"

Cards::Cards(const std::string & color, json dataPacked) :
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not an enum? Color can have only 2 values.
Good idea with taking json as a constructor parameter :)


TEST_F(CardsTests, check_if_call_getOneCard_out_of_range_will_throw_exception)
{
ASSERT_ANY_THROW(redCards.getOneCard(83));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16 is the first number which should throw an exception so it's good to use it in a test.

Copy link
Owner

@ziobron ziobron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor changes can be introduced if you have time.

"15": "Wychodzisz wolny z więzienia. Kartę należy zachować do wykorzystania lub sprzedania."
})"_json;
Cards redCards{"red", dataJson};
json dataJson = R"({"2" : "Wracasz do Madrytu."})"_json;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract a string "Wracasz do Madrytu" to a const and use it here and in line 23 to avoid duplications.

src/Cards.hpp Outdated
@@ -5,9 +5,15 @@
using json = nlohmann::json;
using oneCard = std::string;

enum class CardsColor
{
red,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually values for enum are in UPPERCASE

@codecov-io
Copy link

codecov-io commented Nov 6, 2018

Codecov Report

Merging #13 into master will decrease coverage by 6.82%.
The diff coverage is 85.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #13      +/-   ##
==========================================
- Coverage    93.1%   86.27%   -6.83%     
==========================================
  Files           6       28      +22     
  Lines          29      204     +175     
==========================================
+ Hits           27      176     +149     
- Misses          2       28      +26
Impacted Files Coverage Δ
src/Eurobusiness.hpp 100% <ø> (ø)
src/Property.hpp 100% <ø> (ø) ⬆️
src/Board.hpp 100% <ø> (ø)
src/Player.hpp 100% <ø> (ø) ⬆️
src/Dice.hpp 100% <100%> (ø) ⬆️
src/YouGoToPrison.hpp 100% <100%> (ø)
src/City.cpp 100% <100%> (ø)
src/Roll.cpp 100% <100%> (ø)
src/Cards.hpp 100% <100%> (ø)
src/OrdinaryCard.hpp 100% <100%> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0d72da...4a4df8a. Read the comment docs.

return collectionCards_.at(number);
}

void Cards::doOn(std::shared_ptr<Player> player)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAGNI?

BLUE
};

class Cards : public Field
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the Cards class inherit from the Field class?

src/Field.cpp
src/OrdinaryCard.hpp
src/OrdinaryCard.cpp
src/Railway.hpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many types of cards? They are not needed now. They should be implemented later on requirements like:

Każdorazowe przejście przez pole "Start" lub zatrzymanie się na nim, nagradzane jest wypłacaną przez bank sumą w wysokości 400$, o ile grający nie "udaje się do wiezienia".
Pole "Parking strzeżony" traktowane jest jako pole dodatkowe nie podlegające wykupowi. Osoba znajdująca się swoim pionkiem na tym polu płaci do banku 400$. Pole "Podatek od wzbogacenia" traktowane jest podobnie, przy czym grający wpłaca do banku 200$.
Pole "Darmowy parking" funkcjonuje w grze jako pole nie przynoszące ani zysku ani strat.

A lot of code can be deleted now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[US.1][4] Object representation of cards
4 participants