Skip to content
Snippets Groups Projects
Select Git revision
  • f4b82ecb2ab52b960d89d88339c45a93480a0b4a
  • master default protected
2 results

JoueurTest.java

Blame
  • JoueurTest.java 7.71 KiB
    package ch.hepia;
    
    import static org.junit.Assert.*;
    
    import java.io.ByteArrayOutputStream;
    import java.io.PrintStream;
    
    import org.junit.Test;
    
    public class JoueurTest {
    
        @Test
        public void testAddMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
            joueur.AddMoney(100);
    
            assertEquals(100, joueur.GetMoney(), 0);
        }
    
        @Test
        public void testAddZeroMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
            joueur.AddMoney(0);
    
            assertEquals(0, joueur.GetMoney(), 0);
        }
    
        @Test
        public void testAddNegativeMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.AddMoney(-50));
        }
    
        @Test
        public void testRemoveMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
            joueur.RemoveMoney(10);
    
            assertEquals(90, joueur.GetMoney(), 0);
        }
    
        @Test
        public void testRemoveZeroMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
            joueur.RemoveMoney(0);
    
            assertEquals(0, joueur.GetMoney(), 0);
        }
    
        @Test
        public void testRemoveNegativeMoney() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
    
            assertThrows(RuntimeException.class, () -> joueur.RemoveMoney(-50));
        }
    
        @Test
        public void testAddBet() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
            joueur.SetBet(10, 0);
    
            assertEquals(10, joueur.GetBet(0), 0);
        }
    
        @Test
        public void testAddNegativeBet() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
    
            assertThrows(RuntimeException.class, () -> joueur.SetBet(-10, 0));
        }
    
        @Test
        public void testAddTooBigBet() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
    
            assertThrows(RuntimeException.class, () -> joueur.SetBet(101, 0));
        }
    
        @Test
        public void testAddBetWrongHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
    
            assertThrows(RuntimeException.class, () -> joueur.SetBet(1, 1));
        }
    
        @Test
        public void testGetBetWrongHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 100);
            joueur.SetBet(10, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.GetBet(1));
        }
    
        @Test
        public void testDrawCard() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
            joueur.DrawCard(0, Deck);
    
            assertEquals(3, joueur.GetNbCards(0));
        }
    
        @Test
        public void testDrawCardWrongHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(6, 52));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.DrawCard(1, Deck));
        }
    
        @Test
        public void testCardStrength() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(0, joueur.GetCardStrength(0, 0));
        }
    
        @Test
        public void testCardStrengthWrongCard() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.GetCardStrength(0, 2));
        }
    
        @Test
        public void testCardStrengthWrongHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.GetCardStrength(1, 0));
        }
    
        @Test
        public void testCardCount() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(2, joueur.GetNbCards(0));
        }
    
        @Test
        public void testCardCountWrongHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.GetNbCards(1));
        }
    
        @Test
        public void testShowHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
            System.setOut(new PrintStream(outputStreamCaptor));
    
            joueur.ShowHand(0);
    
            System.setOut(System.out);
            String printedOutput = outputStreamCaptor.toString().trim();
    
            assertTrue(printedOutput.contains("🃟 🃟"));
        }
    
        @Test
        public void testWrongShowHand() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.ShowHand(1));
        }
    
        @Test
        public void testShowHands() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
            System.setOut(new PrintStream(outputStreamCaptor));
    
            joueur.ShowHands();
    
            System.setOut(System.out);
            String printedOutput = outputStreamCaptor.toString().trim();
    
            assertTrue(printedOutput.contains("🃟 🃟"));
        }
    
        @Test
        public void testNumberHands() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(1, joueur.GetNbHands());
        }
    
        @Test
        public void testHandStrength() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(0, joueur.GetStrength(0));
        }
    
        @Test
        public void testWrongHandStrength() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertThrows(RuntimeException.class, () -> joueur.GetStrength(1));
        }
    
        @Test
        public void testDoubled() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(false, joueur.HasDoubled(0));
        }
    
        @Test
        public void testCanSplit() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 2));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            assertEquals(true, joueur.CanSplit(0));
        }
    
        @Test
        public void testCantSplit() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 3));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            joueur.DrawCard(0, Deck);
    
            assertEquals(false, joueur.CanSplit(0));
        }
    
        @Test
        public void testSplit() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 5));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            joueur.Split(0, Deck);
    
            assertEquals(true, joueur.HasSplit(0));
        }
    
        @Test
        public void testSplitMax() {
    
            JeudeCarte Deck = new JeudeCarte(new Paquet(1, 15));
            JoueurHumain joueur = new JoueurHumain(Deck, 0);
    
            joueur.Split(0, Deck);
            joueur.Split(1, Deck);
    
            assertThrows(RuntimeException.class, () -> joueur.Split(0, Deck));
        }
    }