diff --git a/src/main/java/com/github/strangercoug/freecasino/enums/CardRank.java b/src/main/java/com/github/strangercoug/freecasino/enums/CardRank.java index ed42060..1a8a1a9 100644 --- a/src/main/java/com/github/strangercoug/freecasino/enums/CardRank.java +++ b/src/main/java/com/github/strangercoug/freecasino/enums/CardRank.java @@ -35,6 +35,30 @@ * @author Jeffrey Hope */ public enum CardRank { - TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, - ACE, JOKER + TWO("Two"), + THREE("Three"), + FOUR("Four"), + FIVE("Five"), + SIX("Six"), + SEVEN("Seven"), + EIGHT("Eight"), + NINE("Nine"), + TEN("Ten"), + JACK("Jack"), + QUEEN("Queen"), + KING("King"), + ACE("Ace"), + JOKER("Joker"); + + private final String name; + + CardRank(String name){ + this.name = name; + } + + @Override + public String toString() { + return name; + } + } diff --git a/src/main/java/com/github/strangercoug/freecasino/enums/CardSuit.java b/src/main/java/com/github/strangercoug/freecasino/enums/CardSuit.java index fd10184..9be33cd 100644 --- a/src/main/java/com/github/strangercoug/freecasino/enums/CardSuit.java +++ b/src/main/java/com/github/strangercoug/freecasino/enums/CardSuit.java @@ -35,5 +35,21 @@ * @author Jeffrey Hope */ public enum CardSuit { - CLUBS, DIAMONDS, HEARTS, SPADES, BLACK, RED + CLUBS("Clubs"), + DIAMONDS("Diamonds"), + HEARTS("Hearts"), + SPADES("Spades"), + BLACK("Black"), + RED("Red"); + + private final String name; + + CardSuit(String name){ + this.name = name; + } + + @Override + public String toString() { + return name; + } } diff --git a/src/main/java/com/github/strangercoug/freecasino/objs/Card.java b/src/main/java/com/github/strangercoug/freecasino/objs/Card.java index 3dd23c2..8343a34 100644 --- a/src/main/java/com/github/strangercoug/freecasino/objs/Card.java +++ b/src/main/java/com/github/strangercoug/freecasino/objs/Card.java @@ -41,11 +41,6 @@ * @author Jeffrey Hope */ public record Card(CardRank rank, CardSuit suit) implements Comparable { - private static final String[] rankNames = {"Two", "Three", "Four", "Five", "Six", - "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace", - "Joker"}; - private static final String[] suitNames = {"Clubs", "Diamonds", "Hearts", "Spades", - "Black", "Red"}; /** * This method is intended only for baccarat and variants of twenty-one. Use {@code getRank()} if the tens and face @@ -110,9 +105,9 @@ public int compareTo(Card other) { @Override public String toString() { - if (rank == CardRank.JOKER) - return suitNames[suit.ordinal()] + " " + rankNames[rank.ordinal()]; + if (suit == CardSuit.BLACK || suit == CardSuit.RED) + return suit + " " + rank.toString(); - return rankNames[rank.ordinal()] + " of " + suitNames[suit.ordinal()]; + return rank.toString() + " of " + suit.toString(); } } diff --git a/src/test/java/com/github/strangercoug/freecasino/enums/CardRankTest.java b/src/test/java/com/github/strangercoug/freecasino/enums/CardRankTest.java new file mode 100644 index 0000000..9eb9488 --- /dev/null +++ b/src/test/java/com/github/strangercoug/freecasino/enums/CardRankTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2023, Jeffrey Hope + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted (subject to the limitations in the disclaimer + * below) provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY + * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.strangercoug.freecasino.enums; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +class CardRankTest { + + @ParameterizedTest + @MethodSource("cardRankToString") + void testPokerRank(CardRank cardRank, String string) { + assertThat(cardRank.toString(), equalTo(string)); + } + + private static Stream cardRankToString() { + return Stream.of( + arguments(CardRank.TWO, "Two"), + arguments(CardRank.THREE, "Three"), + arguments(CardRank.FOUR, "Four"), + arguments(CardRank.FIVE, "Five"), + arguments(CardRank.SIX, "Six"), + arguments(CardRank.SEVEN, "Seven"), + arguments(CardRank.EIGHT, "Eight"), + arguments(CardRank.NINE, "Nine"), + arguments(CardRank.TEN, "Ten"), + arguments(CardRank.JACK, "Jack"), + arguments(CardRank.QUEEN, "Queen"), + arguments(CardRank.KING, "King"), + arguments(CardRank.ACE, "Ace"), + arguments(CardRank.JOKER, "Joker") + ); + } +} diff --git a/src/test/java/com/github/strangercoug/freecasino/enums/CardSuitTest.java b/src/test/java/com/github/strangercoug/freecasino/enums/CardSuitTest.java new file mode 100644 index 0000000..7f4be7b --- /dev/null +++ b/src/test/java/com/github/strangercoug/freecasino/enums/CardSuitTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2023, Jeffrey Hope + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted (subject to the limitations in the disclaimer + * below) provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY + * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.github.strangercoug.freecasino.enums; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +class CardSuitTest { + + @ParameterizedTest + @MethodSource("cardSuitToString") + void testCardSuit(CardSuit cardSuit, String string) { + assertThat(cardSuit.toString(), equalTo(string)); + } + + private static Stream cardSuitToString() { + return Stream.of( + arguments(CardSuit.CLUBS, "Clubs"), + arguments(CardSuit.DIAMONDS, "Diamonds"), + arguments(CardSuit.HEARTS, "Hearts"), + arguments(CardSuit.SPADES, "Spades"), + arguments(CardSuit.BLACK, "Black"), + arguments(CardSuit.RED, "Red") + ); + } +}