コード例 #1
0
ファイル: blackjacktest.cs プロジェクト: raljoach/Games
        public void GetNumPlayersTest()
        {
            var game = new BlackJackGame();

            //Default number of players
            bool valid = false;
            int defVal = 1;
            var numPlayers = game.GetNumPlayers(string.Empty, defVal, out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(1, numPlayers);

            //Default number of players
            valid = false;
            numPlayers = game.GetNumPlayers("        ", defVal, out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(defVal, numPlayers);

            //Valid
            Random randGen = new Random();
            valid = false;
            numPlayers = game.GetNumPlayers("   " + 1 + "     ", randGen.Next(2), out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(1, numPlayers);

            //Valid
            var r1 = randGen.Next(2, int.MaxValue);
            valid = false;
            numPlayers = game.GetNumPlayers("   " + r1 + "     ", defVal, out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(r1, numPlayers);

            //Valid
            valid = false;
            numPlayers = game.GetNumPlayers(r1.ToString(), defVal, out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(r1, numPlayers);

            //Valid
            valid = false;
            numPlayers = game.GetNumPlayers("\t" + int.MaxValue + "      \t ", defVal, out valid);
            Assert.IsTrue(valid);
            Assert.AreEqual(int.MaxValue, numPlayers);

            //Error
            valid = false;
            numPlayers = game.GetNumPlayers("  " + r1 + "  d    ", defVal, out valid);
            Assert.IsFalse(valid);

            //Error
            valid = false;
            numPlayers = game.GetNumPlayers("    7.1    ", defVal, out valid);
            Assert.IsFalse(valid);

            //Error
            valid = false;
            numPlayers = game.GetNumPlayers("    0    ", defVal, out valid);
            Assert.IsFalse(valid);

            //Error
            valid = false;
            numPlayers = game.GetNumPlayers("    " + int.MinValue + "    ", defVal, out valid);
            Assert.IsFalse(valid);

            //Error
            valid = false;
            numPlayers = game.GetNumPlayers("  " + randGen.Next(int.MinValue + 1, 1) + "   ", defVal, out valid);
            Assert.IsFalse(valid);
        }