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

Add possibility to create Suits from chars #36

Merged
merged 1 commit into from
May 29, 2018
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
7 changes: 7 additions & 0 deletions src/lib/pokerstove/peval/Suit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ Suit::Suit(const std::string& str)
: _suit(suit_code(str[0]))
{}

Suit::Suit(uint8_t c)
{
if (isSuitChar(c))
_suit = suit_code(c);
else
_suit = c;
}

string Suit::str() const
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pokerstove/peval/Suit.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Suit
* object to be created.
*/
explicit Suit(const std::string& str);
explicit Suit(uint8_t c) : _suit(c) {}
explicit Suit(uint8_t c);


/**
Expand Down
38 changes: 38 additions & 0 deletions src/lib/pokerstove/peval/Suit.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <gtest/gtest.h>
#include "Suit.h"

using namespace pokerstove;

const char* suits = "cdhsCDHS";

TEST(Suit, ConstructorChars) {
char suitstr[] = "?";

// test the valid char range
for (int i=0; i<strlen(suits); i++) {
Suit s(suits[i]);
suitstr[0] = suits[i];
EXPECT_STRCASEEQ(suitstr, s.str().c_str());
}
}

TEST(Suit, ConstructorInts) {
char suitstr[] = "?";

// test the valid int range
for (int i=0; i<=3; i++) {
Suit s(i);
suitstr[0] = suits[i];
EXPECT_STREQ(suitstr, s.str().c_str());
}
}

TEST(Suit, ConstructorErrs) {
char suitstr[] = "?";

// test the invalid int range
for (int i=4; i<'C'; i++) {
Suit s(i);
EXPECT_STREQ(suitstr, s.str().c_str());
}
}