This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
package de.knockoutwhist.cards
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import scala.util.Random
|
||||
|
||||
object CardManager {
|
||||
|
||||
|
||||
val cardContainer: Array[Card] = {
|
||||
val cc = new Array[Card](52)
|
||||
var i = 0
|
||||
val cardContainer: List[Card] = {
|
||||
val cc = ListBuffer[Card]()
|
||||
for (suit <- Suit.values) {
|
||||
for (cardValue <- CardValue.values) {
|
||||
cc(i) = Card(cardValue, suit)
|
||||
i+=1
|
||||
cc += Card(cardValue, suit)
|
||||
}
|
||||
}
|
||||
cc
|
||||
cc.toList
|
||||
}
|
||||
private var currentIdx = 0
|
||||
|
||||
@@ -28,6 +27,14 @@ object CardManager {
|
||||
currentIdx += 1
|
||||
card
|
||||
}
|
||||
|
||||
def createHand(amount: Int): Hand = {
|
||||
val hand = ListBuffer[Card]()
|
||||
for (_ <- 1 to amount) {
|
||||
hand += nextCard()
|
||||
}
|
||||
Hand(hand.toList)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
package de.knockoutwhist.cards
|
||||
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
class CardTests extends AnyWordSpec with Matchers{
|
||||
|
||||
"Knock Out Whist" should {
|
||||
"The card container can't be empty" in {
|
||||
CardManager.cardContainer must not be empty
|
||||
}
|
||||
"A deck should have 52 cards" in {
|
||||
CardManager.cardContainer must have size 52
|
||||
}
|
||||
"A deck should have 13 cards of each suit" in {
|
||||
"13 cards of Spades" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Spades) mustBe 13
|
||||
}
|
||||
"13 cards of Hearts" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Hearts) mustBe 13
|
||||
}
|
||||
"13 cards of Diamonds" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Diamonds) mustBe 13
|
||||
}
|
||||
"13 cards of Clubs" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Clubs) mustBe 13
|
||||
}
|
||||
}
|
||||
"A deck should have 4 cards of each value" in {
|
||||
"4 cards of Two" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Two) mustBe 4
|
||||
}
|
||||
"4 cards of Three" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Three) mustBe 4
|
||||
}
|
||||
"4 cards of Four" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Four) mustBe 4
|
||||
}
|
||||
"4 cards of Five" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Five) mustBe 4
|
||||
}
|
||||
"4 cards of Six" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Six) mustBe 4
|
||||
}
|
||||
"4 cards of Seven" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Seven) mustBe 4
|
||||
}
|
||||
"4 cards of Eight" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Eight) mustBe 4
|
||||
}
|
||||
"4 cards of Nine" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Nine) mustBe 4
|
||||
}
|
||||
"4 cards of Ten" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Ten) mustBe 4
|
||||
}
|
||||
"4 cards of Jack" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Jack) mustBe 4
|
||||
}
|
||||
"4 cards of Queen" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Queen) mustBe 4
|
||||
}
|
||||
"4 cards of King" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.King) mustBe 4
|
||||
}
|
||||
"4 cards of Ace" in {
|
||||
CardManager.cardContainer.count(_.cardValue == CardValue.Ace) mustBe 4
|
||||
}
|
||||
}
|
||||
"Check if shuffleAndReset shuffles the deck" in {
|
||||
val originalDeck = CardManager.cardContainer.clone()
|
||||
CardManager.shuffleAndReset()
|
||||
CardManager.cardContainer must not equal originalDeck
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package de.knockoutwhist.cards
|
||||
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.matchers.should.Matchers.should
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
class DeckTests extends AnyWordSpec with Matchers{
|
||||
|
||||
"A deck" should {
|
||||
"The card container can't be empty" in {
|
||||
CardManager.cardContainer must not be empty
|
||||
}
|
||||
"A deck should have 52 cards" in {
|
||||
CardManager.cardContainer must have size 52
|
||||
}
|
||||
"There are 13 cards of spades" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Spades) mustBe 13
|
||||
}
|
||||
"There are 13 cards of hearts" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Hearts) mustBe 13
|
||||
}
|
||||
"There are 13 cards of diamonds" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Diamonds) mustBe 13
|
||||
}
|
||||
"There are 13 cards of clubs" in {
|
||||
CardManager.cardContainer.count(_.suit == Suit.Clubs) mustBe 13
|
||||
}
|
||||
"Check if shuffleAndReset shuffles the deck" in {
|
||||
val originalDeck = List(CardManager.cardContainer)
|
||||
CardManager.shuffleAndReset()
|
||||
val shuffledDeck = CardManager.cardContainer
|
||||
shuffledDeck should not equal originalDeck
|
||||
}
|
||||
"Check if the nextCard method returns a card" in {
|
||||
val nextCard = CardManager.nextCard()
|
||||
nextCard should not be null
|
||||
}
|
||||
"Grab 2 cards from the deck" in {
|
||||
val nextCard = CardManager.nextCard()
|
||||
val nextCard2 = CardManager.nextCard()
|
||||
nextCard should not equal nextCard2
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user