Esempio n. 1
0
        public void TestIfRollDicesReplacesNonUsedIndexes()
        {
            var rngMock = new Mock <IRandom>();

            rngMock.SetupSequence(s => s.Next())
            .Returns(1)     //what random num should .Next() return
            .Returns(4)
            .Returns(4);

            List <int> testList = new List <int>()
            {
                0, 3, 0, 0, 6
            };
            List <int> indexesNotRolled = new List <int> {
                0, 3, 2
            };
            List <int> expected = new List <int>()
            {
                1, 3, 4, 4, 6
            };

            YatzyGame  player = new YatzyGame(new ConsoleActions(), rngMock.Object); //pass in Rng Object
            List <int> result = player.RollDice(testList, indexesNotRolled);

            Assert.Equal(expected, result);
        }
Esempio n. 2
0
        public void TestIfGetIndexesToKeepReturnsKeepNumAsInt()
        {
            //var consoleActionsMock = new Mock<IConsole>();
            //Random randomNum = new Random();
            string[]   eachNumToKeep = { "1", "2", "3" };
            int[]      expected      = { 1, 2, 3 };
            YatzyGame  player        = new YatzyGame(new ConsoleActions(), new Rng());
            List <int> result        = player.IndexesToKeepAsInt(eachNumToKeep);

            Assert.Equal(expected, result);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var consoleReader = new ConsoleReader();
            var player        = new Player(consoleReader);
            var scoreCard     = new ScoreCard();
            var rng           = new Rng();
            var yatzy         = new YatzyGame(player, scoreCard, rng);

            Display.WelcomeMessage();
            yatzy.PlayGame();
        }
Esempio n. 4
0
        public void TestToSeeIfCalculateSumReturnsSum()
        {
            List <int> testNumbers = new List <int>()
            {
                3, 4, 5, 5, 2
            };
            int       expected = 19;
            YatzyGame player   = new YatzyGame(new ConsoleActions(), new Rng());
            int       result   = player.CalculateSum(testNumbers);

            Assert.Equal(expected, result);
        }
Esempio n. 5
0
        public void GameShouldThrowRoundOverExceptionWhenRollsExceeded()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput()).Returns("r").Returns("r").Returns("r").Returns("q");
            var player    = new Player(mockInput.Object);
            var scoreCard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scoreCard, mockRng.Object);

            Assert.Throws <RoundOverException>(() => yatzy.PlayGame());
        }
Esempio n. 6
0
        public void TestToSeeIfFiveNumbersGenerated()
        {
            // var consoleActionsMock = new Mock<IConsole>();
            // var randomNum = new Mock<IRandom>();
            List <int> testNumbers = new List <int>()
            {
                3, 4, 5, 5, 2
            };
            int       expected = 5;
            YatzyGame player   = new YatzyGame(new ConsoleActions(), new Rng());
            int       result   = player.GenerateFiveNumbers().Count;

            Assert.Equal(expected, result);
        }
Esempio n. 7
0
        public void TestIfDetermineIndexesNotKeptReturnsCorrectList()
        {
            List <int> testList = new List <int>()
            {
                0, 3, 0, 0, 6
            };
            List <int> expected = new List <int>()
            {
                0, 2, 3
            };
            YatzyGame  player = new YatzyGame(new ConsoleActions(), new Rng());
            List <int> result = player.DetermineIndexesNotKept(testList);

            Assert.Equal(expected, result);
        }
Esempio n. 8
0
        public void GameShouldEndWhenUserRespondsQuit()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.Setup(consoleReader => consoleReader.GetInput()).Returns("q");
            var player    = new Player(mockInput.Object);
            var scoreCard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scoreCard, mockRng.Object);

            yatzy.PlayGame();
            Assert.False(yatzy.IsPlayingGame);
        }
Esempio n. 9
0
        public void GameShouldStartARoundByRolling5Dice()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput()).Returns("r").Returns("q");
            var player    = new Player(mockInput.Object);
            var scoreCard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scoreCard, mockRng.Object);

            yatzy.PlayRound();
            Assert.NotEqual(0, yatzy.DiceCup[0].Value);
        }
Esempio n. 10
0
        public void CategoryShouldBeUsedIfScoredInCategory()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.Setup(consoleReader => consoleReader.GetInput()).Returns("a");
            var player    = new Player(mockInput.Object);
            var scoreCard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scoreCard, mockRng.Object);

            Assert.False(scoreCard.CategoryScoreCard[0].IsUsed);
            yatzy.PlayRound();
            Assert.True(scoreCard.CategoryScoreCard[0].IsUsed);
        }
Esempio n. 11
0
        public void TestIfKeepNumPutsNumbersSpecifiedByUserInAnArray()
        {
            var consoleActionsMock = new Mock <IConsole>();

            consoleActionsMock.Setup(s => s.ReadLine())
            .Returns("1,2,3");     //fake readline
            // List<int> testNumbers = new List<int>();
            // int[] array = new int[] {3, 4, 5, 5, 2};
            // testNumbers.AddRange(array);
            // int[] heldNumbers = {1,2,3};
            string[]  expected = { "1", "2", "3" };
            YatzyGame player   = new YatzyGame(consoleActionsMock.Object, new Rng());

            string[] result = player.GetIndexesUserWantsToKeep();
            Assert.Equal(expected, result);
        }
Esempio n. 12
0
        public void GameShouldEndWhenAllCategoriesScored()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);

            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput()).Returns("a").Returns("b").Returns("c").Returns("d").Returns("e").Returns("f").Returns("g").Returns("h").Returns("i").Returns("j").Returns("k").Returns("l").Returns("m").Returns("n").Returns("o");

            var player    = new Player(mockInput.Object);
            var scoreCard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scoreCard, mockRng.Object);

            yatzy.PlayGame();
            Assert.False(yatzy.IsPlayingGame);
        }
Esempio n. 13
0
        public void TestIfIndexesNotSpecifiedByUserIsRemoved()
        {
            //MORE TEST CASES
            List <int> eachNumToKeepAsInt = new List <int>()
            {
                1, 2, 3
            };
            List <int> testOfFiveNumbers = new List <int>()
            {
                3, 4, 5, 5, 2
            };

            int[]      expected = { 3, 4, 5, 0, 0 };
            YatzyGame  player   = new YatzyGame(new ConsoleActions(), new Rng());
            List <int> result   = player.KeepIndexesSpecifiedByUser(eachNumToKeepAsInt, testOfFiveNumbers);

            Assert.Equal(expected, result);
        }
Esempio n. 14
0
        public void HeldDiceShouldNotGetRerolled()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput())
            .Returns("1,1,1")
            .Returns("q");
            var player    = new Player(mockInput.Object);
            var scorecard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scorecard, mockRng.Object);
            var round     = new Round();

            round.RollDice(yatzy.DiceCup, mockRng.Object);
            yatzy.HandleResponse(player.Respond(), round);
            Assert.Equal(3, yatzy.DiceCup.Count(die => die.IsHeld));
        }
Esempio n. 15
0
        public void TestToAfterReRollMakesAUnionOfTwoLists()
        {
            List <int> newList = new List <int>()
            {
                0, 4, 0, 5, 0
            };
            List <int> reRolledNumbers = new List <int>()
            {
                3, 0, 5, 0, 2
            };
            List <int> expected = new List <int>()
            {
                3, 4, 5, 5, 2
            };
            YatzyGame  player = new YatzyGame(new ConsoleActions(), new Rng());
            List <int> result = player.AfterReRoll(newList, reRolledNumbers);

            Assert.Equal(expected, result);
        }
Esempio n. 16
0
        public void GameShouldNotScoreIfUsed()
        {
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput()).Returns("a").Returns("a").Returns("q");
            var player    = new Player(mockInput.Object);
            var response  = player.Respond();
            var scorecard = new ScoreCard();
            var round     = new Round();
            var yatzy     = new YatzyGame(player, scorecard, mockRng.Object);

            yatzy.PlayRound();
            Assert.Equal(ResponseType.ScoreInCategory, response.ResponseType);
            yatzy.HandleResponse(response, round);
            Assert.Equal(ResponseType.InvalidResponse, response.ResponseType);
        }
Esempio n. 17
0
        public void InputForNonExistentDieReturnsInvalid()
        {
            var mockInput = new Mock <IConsoleReader>();

            mockInput.SetupSequence(consoleReader => consoleReader.GetInput())
            .Returns("2")
            .Returns("q");
            var mockRng = new Mock <IRng>();

            mockRng.Setup(rng => rng.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(1);
            var player    = new Player(mockInput.Object);
            var scorecard = new ScoreCard();
            var yatzy     = new YatzyGame(player, scorecard, mockRng.Object);
            var round     = new Round();

            round.RollDice(yatzy.DiceCup, mockRng.Object);
            var response = player.Respond();

            Round.HoldDice(response, yatzy.DiceCup);
            Assert.Equal(ResponseType.InvalidResponse, response.ResponseType);
        }