Skip to content

Commit

Permalink
Merge pull request #12 from heindrichpaul/feature/fixing-report
Browse files Browse the repository at this point in the history
Feature/fixing report
  • Loading branch information
heindrichpaul authored Mar 29, 2019
2 parents 695867d + a00db1e commit 076b05c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 53 deletions.
10 changes: 5 additions & 5 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type cardError struct {
}

func newCard(deckID, value, suit string) (card *Card, err error) {

if !strings.EqualFold(deckID, "") {

card = &Card{
Expand All @@ -43,7 +43,7 @@ func newCard(deckID, value, suit string) (card *Card, err error) {
if err != nil {
return card, err
}

card.Code = fmt.Sprintf("%s%s", value, suit)
if !strings.EqualFold("*", value) && !strings.EqualFold("*", suit) {
card.Image = fmt.Sprintf("https://deckofcardsapi.com/static/img/%s.png", card.Code)
Expand All @@ -55,7 +55,7 @@ func newCard(deckID, value, suit string) (card *Card, err error) {
return
}

func getValue(value string ) (result string, err error) {
func getValue(value string) (result string, err error) {

values := regexp.MustCompile(`[2-9]|0|A|K|Q|J|\*`)
if !values.MatchString(value) {
Expand All @@ -79,7 +79,7 @@ func getValue(value string ) (result string, err error) {
result = value
}

return
return
}

func getSuit(suit string) (result string, err error) {
Expand All @@ -102,7 +102,7 @@ func getSuit(suit string) (result string, err error) {
result = "NONE"
}

return
return
}

//String function serializes the Card struct into a representable string output.
Expand Down
54 changes: 30 additions & 24 deletions card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ func cardCreatorHelper(deckID, suit, value string, t *testing.T) {
t.Logf("Failed to verify card code for: %s%s expected: %s\n", value, suit, card.Code)
t.FailNow()
}
CheckSuit(t, card, value, suit)
CheckValue(t, card, value, suit)

if card.drawn {
t.Logf("Failed to verify card drawn flag for: %s%s expected: false but received: %t\n", value, suit, card.drawn)
t.FailNow()
}

if strings.Compare(card.Image, "") != 0 {
resp, err := http.Get(card.Image)
if err != nil {
t.Error(err.Error())
}
if resp.StatusCode != 200 {
t.Errorf("Unable to find image %s\n", card.Image)
}
}

if !strings.EqualFold(card.DeckID, TestDECKID) {
t.Logf("The DeckID is not correctly stored on the creation of a new card.\n")
t.FailNow()

}

t.Log("Finished running " + fmt.Sprintf("%s%s", value, suit) + ": " + time.Now().String())
}

func CheckSuit(t *testing.T, card *Card, value, suit string) {
switch suit {
case "S":
if !strings.EqualFold(card.Suit, "SPADES") {
Expand Down Expand Up @@ -67,7 +95,9 @@ func cardCreatorHelper(deckID, suit, value string, t *testing.T) {
t.FailNow()
}
}
}

func CheckValue(t *testing.T, card *Card, value, suit string) {
switch value {
case "A":
if !strings.EqualFold(card.Value, "ACE") {
Expand Down Expand Up @@ -105,31 +135,7 @@ func cardCreatorHelper(deckID, suit, value string, t *testing.T) {
t.FailNow()
}
}

if card.drawn {
t.Logf("Failed to verify card drawn flag for: %s%s expected: false but received: %t\n", value, suit, card.drawn)
t.FailNow()
}

if strings.Compare(card.Image, "") != 0 {
resp, err := http.Get(card.Image)
if err != nil {
t.Error(err.Error())
}
if resp.StatusCode != 200 {
t.Errorf("Unable to find image %s\n", card.Image)
}
}

if !strings.EqualFold(card.DeckID, TestDECKID) {
t.Logf("The DeckID is not correctly stored on the creation of a new card.\n")
t.FailNow()

}

t.Log("Finished running " + fmt.Sprintf("%s%s", value, suit) + ": " + time.Now().String())
}

func TestNewCardWithInvalidSuit(t *testing.T) {
suit := ""
value := "0"
Expand Down
24 changes: 0 additions & 24 deletions deck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,6 @@ func TestInjectionOfUnsupportedSuitWhileRunningNewDeckWithJoker(t *testing.T) {

func TestShuffleDeck(t *testing.T) {
deck := NewDeckWithJokers(1)
if deck == nil {
t.Logf("Failed to create deck\n")
t.FailNow()
}
if !deck.Success {
t.Logf("Deck not properly initialized. Expected a success on a successful creation\n")
t.FailNow()
}
if deck.Remaining != len(deck.cards) && len(deck.cards) != 54 {
t.Logf("Deck not properly initialized. Expected amount of cards remaining and the length of the cards slice to be equavalent after a new deck is created.\n")
t.FailNow()
}
if strings.EqualFold(deck.DeckID, "\n") {
t.Logf("Deck not properly initialized. Expected a non empty DeckID\n")
t.FailNow()
}
if deck.Shuffled {
t.Logf("Deck not properly initialized. Expected an unshuffled deck\n")
t.FailNow()
}
if !strings.EqualFold(deck.cards[53].Value, "JOKER\n") && !strings.EqualFold(deck.cards[53].Suit, "NONE") && !strings.EqualFold(deck.cards[52].Value, "JOKER") && !strings.EqualFold(deck.cards[52].Suit, "NONE") {
t.Logf("Deck not properly initialized. Expected last two cards on an unshuffled deck to be JOKERS.\n")
t.FailNow()
}
t.Logf("Deck is being shuffled\n")
deck = ShuffleDeck(deck)
if !deck.Shuffled {
Expand Down

0 comments on commit 076b05c

Please sign in to comment.