Skip to content

Commit

Permalink
Add CardTest and HandTest, update Card API
Browse files Browse the repository at this point in the history
  • Loading branch information
AvengerMoJo committed Aug 6, 2011
1 parent f4eb50d commit 28cc626
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/CardTest.cpp
@@ -0,0 +1,68 @@
#include <iostream>
#include "Card.h"

using namespace std;

typedef Card* Card_p;

void printCard( Card_p* cards ){
for( int s=0; s<SUITSIZE; s++){
for( int v=0; v<CARDVALUESIZE; v++){
cout << cards[s*13+v]->toString();
}
cout << endl;
}
cout << endl;
}
void printHashValue( Card_p* cards ){
for( int s=0; s<SUITSIZE; s++){
for( int v=0; v<CARDVALUESIZE; v++){
cout << cards[s*13+v]->toString() << cards[s*13+v]->getHashString() << endl;
}
cout << endl;
}
cout << endl;
}

void inputExpectedValue( Card_p* cards ){
for( int s=0; s<SUITSIZE; s++){
for( int v=0; v<CARDVALUESIZE; v++){
cards[s*13+v]->setSuit(Card::Suit(s+1));
cards[s*13+v]->setValue(Card::CardValue(v+1));
}
}
}
void inputUnexpectedValue( Card_p* cards ){
for( int s=0; s<SUITSIZE; s++){
for( int v=0; v<CARDVALUESIZE; v++){
cards[s*13+v]->setSuit(Card::Suit(-s*2));
cards[s*13+v]->setValue(Card::CardValue(-v*2));
}
}
printCard(cards);
}

void createExpectedCard( Card_p* cards ){
for( int s=0; s<SUITSIZE; s++){
for( int v=0; v<CARDVALUESIZE; v++){
cards[s*13+v]= new Card();
}
}
inputExpectedValue( cards );
printCard(cards);
}



int main(){
Card_p cards[52];
createExpectedCard( cards );
printHashValue( cards );
inputUnexpectedValue( cards );
printHashValue( cards );
Card::Suit(-1);
Card::CardValue(-1);

return 0;
}

83 changes: 83 additions & 0 deletions test/HandTest.cpp
@@ -0,0 +1,83 @@
#include <iostream>
#include "Deck.h"
#include "Hand.h"

using namespace std;

void play( Deck* myDeck )
{
Hand myHand;
Card* hole[2];
Card* flop[3];
Card* turn;
Card* river;

hole[0] = myDeck->popCard();
hole[1] = myDeck->popCard();

std::cout << "My first card " << hole[0]->toString() << endl;
std::cout << "My second card " << hole[1]->toString() << endl;
myHand.setHole( hole[0], hole[1] );
std::cout << "My Hands has flush " << boolalpha << myHand.isFlush() << endl;
std::cout << "My Hands has straight " << boolalpha << myHand.isStraight() << endl;
std::cout << "My Hands has straight flush " << boolalpha << myHand.isStraightFlush() << endl;

myDeck->getFlop( flop[0], flop[1], flop[2] );
std::cout << "Flop Cards " << flop[0]->toString() << flop[1]->toString() << flop[2]->toString() << endl;
myHand.setFlop( flop[0], flop[1], flop[2] );
std::cout << "My Hands has flush " << boolalpha << myHand.isFlush() << endl;
std::cout << "My Hands has straight " << boolalpha << myHand.isStraight() << endl;
std::cout << "My Hands has full house " << boolalpha << myHand.isFullHouse() << endl;
std::cout << "My Hands has four of a kind " << boolalpha << myHand.isFourOfAKind() << endl;
std::cout << "My Hands has straight flush " << boolalpha << myHand.isStraightFlush() << endl;
std::cout << "My Hands has three of a kind " << boolalpha << myHand.isThreeOfAKind() << endl;
std::cout << "My Hands has pair " << boolalpha << myHand.isPair() << endl;

turn = myDeck->getTurn();
std::cout << "Turn card " << turn->toString() << endl;
myHand.setTurn( turn );
std::cout << "My Hands has flush " << boolalpha << myHand.isFlush() << endl;
std::cout << "My Hands has straight " << boolalpha << myHand.isStraight() << endl;
std::cout << "My Hands has full house " << boolalpha << myHand.isFullHouse() << endl;
std::cout << "My Hands has four of a kind " << boolalpha << myHand.isFourOfAKind() << endl;
std::cout << "My Hands has straight flush " << boolalpha << myHand.isStraightFlush() << endl;
std::cout << "My Hands has three of a kind " << boolalpha << myHand.isThreeOfAKind() << endl;
std::cout << "My Hands has pair " << boolalpha << myHand.isPair() << endl;

river = myDeck->getRiver();
std::cout << "River card " << river->toString() << endl;
myHand.setRiver( river );
std::cout << "My Hands has flush " << boolalpha << myHand.isFlush() << endl;
std::cout << "My Hands has straight " << boolalpha << myHand.isStraight() << endl;
std::cout << "My Hands has full house " << boolalpha << myHand.isFullHouse() << endl;
std::cout << "My Hands has four of a kind " << boolalpha << myHand.isFourOfAKind() << endl;
std::cout << "My Hands has straight flush " << boolalpha << myHand.isStraightFlush() << endl;
std::cout << "My Hands has three of a kind " << boolalpha << myHand.isThreeOfAKind() << endl;
std::cout << "My Hands has pair " << boolalpha << myHand.isPair() << endl;
}

int main(){
Deck myDeck;
std::cout << "New Deck of Card" << endl;
std::cout << myDeck.toString() << endl;

myDeck.quickShuffle();
std::cout << "Quick Shuffle" << endl;
std::cout << myDeck.toString() << endl;

myDeck.riffleShuffle();
std::cout << "Riffle Shuffle" << endl;
std::cout << myDeck.toString() << endl;

//for( int i=0; i< 100000; i++ ){
for( int i=0; i< 8; i++ ){
Deck myDeck2;
myDeck2.quickShuffle();
myDeck2.riffleShuffle();
std::cout << myDeck2.toString() << endl;
play( &myDeck2 );
}

return 0;
}

0 comments on commit 28cc626

Please sign in to comment.