From f79fe61b0eeac77866e50436fb44fb08032e4f41 Mon Sep 17 00:00:00 2001 From: Heindrich Paul Date: Fri, 29 Mar 2019 20:39:33 +0100 Subject: [PATCH 1/3] fixed file formatting --- card.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/card.go b/card.go index e044f6a..d0a98b3 100644 --- a/card.go +++ b/card.go @@ -23,7 +23,7 @@ type cardError struct { } func newCard(deckID, value, suit string) (card *Card, err error) { - + if !strings.EqualFold(deckID, "") { card = &Card{ @@ -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) @@ -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) { @@ -79,7 +79,7 @@ func getValue(value string ) (result string, err error) { result = value } - return + return } func getSuit(suit string) (result string, err error) { @@ -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. From 75f90bd97c3f1fb8572ff67511ed438facd526fc Mon Sep 17 00:00:00 2001 From: Heindrich Paul Date: Fri, 29 Mar 2019 20:46:41 +0100 Subject: [PATCH 2/3] fixing complexity in tests --- card_test.go | 54 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/card_test.go b/card_test.go index f3c1634..569df05 100644 --- a/card_test.go +++ b/card_test.go @@ -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") { @@ -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") { @@ -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" From a00db1eb5eaaca040b4dbab89871c60c3e662525 Mon Sep 17 00:00:00 2001 From: Heindrich Paul Date: Fri, 29 Mar 2019 22:01:31 +0100 Subject: [PATCH 3/3] fixed complexity of tests --- deck_test.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/deck_test.go b/deck_test.go index 8340aab..ee076e5 100644 --- a/deck_test.go +++ b/deck_test.go @@ -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 {