Fixed Tests
This commit is contained in:
@@ -31,7 +31,7 @@ object TUIMain extends CustomThread with EventListener with UI {
|
||||
|
||||
setName("TUI")
|
||||
|
||||
private var init = false
|
||||
var init = false
|
||||
private var internState: GameState = GameState.NO_SET
|
||||
|
||||
override def instance: CustomThread = TUIMain
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package de.knockoutwhist.cards
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.base.CardBaseManager
|
||||
import de.knockoutwhist.testutils.TestUtil
|
||||
import de.knockoutwhist.ui.tui.TUIMain.TUICards.renderCardAsString
|
||||
@@ -41,9 +42,10 @@ class CardTests extends AnyWordSpec with Matchers{
|
||||
renderCardAsString(Card(CardValue.Ten, Suit.Spades)) shouldBe expectedResult
|
||||
}
|
||||
"be able to reset the order" in {
|
||||
CardBaseManager.shuffleAndReset()
|
||||
CardBaseManager.resetOrder()
|
||||
val card = CardBaseManager.nextCard()
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
cardManager.shuffleAndReset()
|
||||
cardManager.resetOrder()
|
||||
val card = cardManager.nextCard()
|
||||
card.suit shouldBe Suit.Spades
|
||||
card.cardValue shouldBe CardValue.Two
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.cards
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.base.CardBaseManager
|
||||
import de.knockoutwhist.testutils.TestUtil
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
@@ -11,50 +12,56 @@ class DeckTests extends AnyWordSpec with Matchers{
|
||||
"A deck" should {
|
||||
TestUtil.disableDelay()
|
||||
"not be empty" in {
|
||||
CardBaseManager.cardContainer must not be empty
|
||||
KnockOutWhist.config.cardManager.cardContainer must not be empty
|
||||
}
|
||||
"have 52 cards" in {
|
||||
CardBaseManager.cardContainer must have size 52
|
||||
KnockOutWhist.config.cardManager.cardContainer must have size 52
|
||||
}
|
||||
"contain 13 cards of spades" in {
|
||||
CardBaseManager.cardContainer.count(_.suit == Suit.Spades) mustBe 13
|
||||
KnockOutWhist.config.cardManager.cardContainer.count(_.suit == Suit.Spades) mustBe 13
|
||||
}
|
||||
"contain 13 cards of hearts" in {
|
||||
CardBaseManager.cardContainer.count(_.suit == Suit.Hearts) mustBe 13
|
||||
KnockOutWhist.config.cardManager.cardContainer.count(_.suit == Suit.Hearts) mustBe 13
|
||||
}
|
||||
"contain 13 cards of diamonds" in {
|
||||
CardBaseManager.cardContainer.count(_.suit == Suit.Diamonds) mustBe 13
|
||||
KnockOutWhist.config.cardManager.cardContainer.count(_.suit == Suit.Diamonds) mustBe 13
|
||||
}
|
||||
"contain 13 cards of clubs" in {
|
||||
CardBaseManager.cardContainer.count(_.suit == Suit.Clubs) mustBe 13
|
||||
KnockOutWhist.config.cardManager.cardContainer.count(_.suit == Suit.Clubs) mustBe 13
|
||||
}
|
||||
"have cards in a different order after shuffling it" in {
|
||||
val originalDeck = List(CardBaseManager.cardContainer)
|
||||
CardBaseManager.shuffleAndReset()
|
||||
val shuffledDeck = CardBaseManager.cardContainer
|
||||
val originalDeck = List(KnockOutWhist.config.cardManager)
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
cardManager.shuffleAndReset()
|
||||
val shuffledDeck = KnockOutWhist.config.cardManager
|
||||
shuffledDeck should not equal originalDeck
|
||||
}
|
||||
"provide cards" in {
|
||||
val nextCard = CardBaseManager.nextCard()
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
val nextCard = cardManager.nextCard()
|
||||
nextCard should not be null
|
||||
}
|
||||
"provide different cards" in {
|
||||
val nextCard = CardBaseManager.nextCard()
|
||||
val nextCard2 = CardBaseManager.nextCard()
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
val nextCard = cardManager.nextCard()
|
||||
val nextCard2 = cardManager.nextCard()
|
||||
nextCard should not equal nextCard2
|
||||
}
|
||||
"supply a hand of 7 cards for the first round" in {
|
||||
val hand = CardBaseManager.createHand()
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
val hand = cardManager.createHand()
|
||||
hand.cards should have size 7
|
||||
}
|
||||
"supply a hand of 2 cards" in {
|
||||
val hand = CardBaseManager.createHand(2)
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
val hand = cardManager.createHand(2)
|
||||
hand.cards should have size 2
|
||||
}
|
||||
"throw an exception if you request more then 52 cards without shuffling" in {
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
assertThrows[IndexOutOfBoundsException] {
|
||||
for (_ <- 1 to 53) {
|
||||
CardBaseManager.nextCard()
|
||||
cardManager.nextCard()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.matchers.should.Matchers.{should, shouldBe}
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class DefaultConfigurationTests extends AnyWordSpec with Matchers{
|
||||
"The Configuration by default" should {
|
||||
"select MainLogic for the main component" in {
|
||||
@@ -29,15 +31,12 @@ class DefaultConfigurationTests extends AnyWordSpec with Matchers{
|
||||
"select TrickLogic for the trick component" in {
|
||||
DefaultConfiguration.trickcomponent shouldBe TrickLogic
|
||||
}
|
||||
"select CardBaseManager for the cardManager" in {
|
||||
DefaultConfiguration.cardManager shouldBe CardBaseManager
|
||||
}
|
||||
"select RoundLogic for the round logic component" in {
|
||||
DefaultConfiguration.roundlogcomponent shouldBe RoundLogic
|
||||
}
|
||||
|
||||
"create a CustomPlayerBaseQueue as the right Queue" in {
|
||||
val player1 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val queue = new CustomPlayerBaseQueue(Array(player1), 0)
|
||||
val rightQueue = DefaultConfiguration.createRightQueue(Array(player1), 0)
|
||||
rightQueue.currentIndex shouldBe queue.currentIndex
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.matchers.should.Matchers.{should, shouldBe}
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class MatchControllerTests extends AnyWordSpec with Matchers {
|
||||
|
||||
"The enter players function" should {
|
||||
@@ -22,7 +24,7 @@ class MatchControllerTests extends AnyWordSpec with Matchers {
|
||||
TestUtil.cancelOut() {
|
||||
TestUtil.simulateInput("foo,bar\n") {
|
||||
ControlThread.runLater {
|
||||
MainLogic.startMatch() should not be(List(PlayerFactory.createPlayer("foo", HUMAN), PlayerFactory.createPlayer("bar", HUMAN)))
|
||||
MainLogic.startMatch() should not be(List(PlayerFactory.createPlayer("foo", UUID.randomUUID(), HUMAN), PlayerFactory.createPlayer("bar", UUID.randomUUID(), HUMAN)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.logic
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
||||
import de.knockoutwhist.control.ControlThread
|
||||
import de.knockoutwhist.control.controllerBaseImpl.MainLogic
|
||||
@@ -10,19 +11,21 @@ import de.knockoutwhist.testutils.TestUtil
|
||||
import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
|
||||
class CtrRoundTests extends AnyWordSpec with Matchers {
|
||||
"Control Round" should {
|
||||
TestUtil.disableDelay()
|
||||
"Work" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val hand1 = Hand(List(Card(CardValue.Two, Suit.Hearts), Card(CardValue.Three, Suit.Hearts)))
|
||||
val hand2 = Hand(List(Card(CardValue.Four, Suit.Hearts), Card(CardValue.Five, Suit.Hearts)))
|
||||
player1.provideHand(hand1)
|
||||
player2.provideHand(hand2)
|
||||
val round1 = Round(Suit.Spades, List(), List(player1, player2), List(), 0, player1, false)
|
||||
val match1 = Match(List(player1, player2), 2, true, List(round1))
|
||||
val match1 = Match(List(player1, player2), 2, true, List(round1), KnockOutWhist.config.cardManager)
|
||||
ControlThread.runLater {
|
||||
TestUtil.simulateInput("2\n") {
|
||||
MainLogic.controlRound(match1, round1)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.logic
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.CardValue.{Ace, Seven, Six, Ten}
|
||||
import de.knockoutwhist.cards.Suit.{Clubs, Spades}
|
||||
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
||||
@@ -14,6 +15,7 @@ import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.matchers.should.Matchers.shouldBe
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import java.util.UUID
|
||||
import scala.collection.{immutable, mutable}
|
||||
|
||||
class MainLogicTests extends AnyWordSpec with Matchers {
|
||||
@@ -22,7 +24,7 @@ class MainLogicTests extends AnyWordSpec with Matchers {
|
||||
"check whether the card played was the first card played in the trick and return the correct trick" in {
|
||||
val trick1 = Trick()
|
||||
val card1 = Card(Ace, Spades)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
ControlThread.runLater {
|
||||
MainLogic.playCard(trick1, card1, player1) shouldBe Trick(firstCard = Some(card1), cards = immutable.HashMap(card1 -> player1))
|
||||
}
|
||||
@@ -31,7 +33,7 @@ class MainLogicTests extends AnyWordSpec with Matchers {
|
||||
val firstcard = Card(Ten, Clubs)
|
||||
val trick1 = Trick(firstCard = Some(firstcard))
|
||||
val card1 = Card(Ace, Spades)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
ControlThread.runLater {
|
||||
MainLogic.playCard(trick1, card1, player1) shouldBe Trick(firstCard = Some(firstcard), cards = immutable.HashMap(card1 -> player1))
|
||||
}
|
||||
@@ -45,8 +47,8 @@ class MainLogicTests extends AnyWordSpec with Matchers {
|
||||
}
|
||||
}
|
||||
"be able to insert the entered Players into the match data structure start with the trick by asking the player for a card" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
ControlThread.runLater {
|
||||
MainLogic.enteredPlayers(List(player1, player2))
|
||||
}
|
||||
@@ -54,19 +56,19 @@ class MainLogicTests extends AnyWordSpec with Matchers {
|
||||
}
|
||||
"controlMatch" should {
|
||||
"check if the current match is already finished and if so, show who won etc." in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val round1 = Round(Suit.Spades, List(), List(player1), List(), 0, player1, false)
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1)) //a finished Match
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1), KnockOutWhist.config.cardManager) //a finished Match
|
||||
ControlThread.runLater {
|
||||
MainLogic.controlMatch(match1)
|
||||
}
|
||||
}
|
||||
"check if the current match is already finished and if not, get the remaining players and continue" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val round1 = Round(Suit.Spades, List(), List(player1, player2), List(), 0, player1, false)
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1))
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1), KnockOutWhist.config.cardManager)
|
||||
ControlThread.runLater {
|
||||
MainLogic.controlMatch(match1)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.logic
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.Suit
|
||||
import de.knockoutwhist.control.controllerBaseImpl.MatchLogic
|
||||
import de.knockoutwhist.player.PlayerFactory
|
||||
@@ -9,20 +10,22 @@ import org.scalatest.matchers.must.Matchers
|
||||
import org.scalatest.matchers.should.Matchers.shouldBe
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class MatchLogicTests extends AnyWordSpec with Matchers {
|
||||
|
||||
"The Match logic" should {
|
||||
"check the already finished rounds and return false when it is empty (because the Match can't be finished" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val match1 = Match(List(player1, player2), 5, true, List())
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val match1 = Match(List(player1, player2), 5, true, List(), KnockOutWhist.config.cardManager)
|
||||
MatchLogic.isOver(match1) shouldBe false
|
||||
}
|
||||
"return true when calling isOver if the match is over" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val round1 = new Round(Suit.Spades, List(player1), false)
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1))
|
||||
val match1 = Match(List(player1, player2), 5, true, List(round1), KnockOutWhist.config.cardManager)
|
||||
MatchLogic.isOver(match1) shouldBe true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.player
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.{Card, CardValue, Hand, Suit}
|
||||
import de.knockoutwhist.control.ControlThread
|
||||
import de.knockoutwhist.control.controllerBaseImpl.TrickLogic
|
||||
@@ -9,6 +10,8 @@ import org.scalatest.wordspec.AnyWordSpec
|
||||
import de.knockoutwhist.player.StubPlayer
|
||||
import de.knockoutwhist.rounds.{Match, Round, Trick}
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
class StubPlayerTests extends AnyWordSpec with Matchers {
|
||||
"The StubPlayer" should {
|
||||
"be able to provide a hand" in {
|
||||
@@ -26,14 +29,14 @@ class StubPlayerTests extends AnyWordSpec with Matchers {
|
||||
"be able to set the doglife" in {
|
||||
val hand1 = Hand(List(Card(CardValue.Two, Suit.Hearts), Card(CardValue.Three, Suit.Hearts)))
|
||||
val player1 = StubPlayer("Gunter", Some(hand1))
|
||||
player1.setDogLife() shouldBe StubPlayer("Gunter", Some(hand1), true)
|
||||
player1.setDogLife() shouldBe StubPlayer("Gunter", Some(hand1), UUID.randomUUID(), true)
|
||||
}
|
||||
"be able to handle a Card played" in {
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", HUMAN)
|
||||
val player1 = PlayerFactory.createPlayer("Gunter", UUID.randomUUID(), HUMAN)
|
||||
val player2 = PlayerFactory.createPlayer("Peter", UUID.randomUUID(), HUMAN)
|
||||
val round1 = Round(Suit.Spades, List(), List(player1, player2), List(), 0, player1, false)
|
||||
val trick1 = Trick()
|
||||
val match1 = Match(List(player1, player2), 5, false, List(round1))
|
||||
val match1 = Match(List(player1, player2), 5, false, List(round1), KnockOutWhist.config.cardManager)
|
||||
val hand1 = Hand(List(Card(CardValue.Two, Suit.Hearts), Card(CardValue.Three, Suit.Hearts)))
|
||||
val hand2 = Hand(List(Card(CardValue.Four, Suit.Hearts), Card(CardValue.Five, Suit.Hearts)))
|
||||
player1.provideHand(hand1)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.knockoutwhist.rounds
|
||||
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
import de.knockoutwhist.cards.base.CardBaseManager
|
||||
import de.knockoutwhist.testutils.TestUtil
|
||||
import de.knockoutwhist.ui.tui.TUIMain
|
||||
@@ -16,9 +17,10 @@ class GameplayTests extends AnyWordSpec with Matchers {
|
||||
"not throw an exception" in {
|
||||
TestUtil.enableDebugMode()
|
||||
DelayHandler.activateDelay = false
|
||||
val cardManager = KnockOutWhist.config.cardManager
|
||||
//TestUtil.disableDelay()
|
||||
CardBaseManager.shuffleAndReset()
|
||||
CardBaseManager.resetOrder()
|
||||
cardManager.shuffleAndReset()
|
||||
cardManager.resetOrder()
|
||||
//TestUtil.cancelOut() {
|
||||
TestUtil.simulateInput("a\n5\n1\nLeon,Janis\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\ny\n1\n1\n1\n2\n") {
|
||||
TUIMain.initial
|
||||
|
||||
Reference in New Issue
Block a user