Example #1
0
        public bool TestRandom()
        {
            Dictionary <string, int> _dict = new Dictionary <string, int>();
            Poker poker     = Poker.Singleton;
            int   randomNum = 0;

            for (int i = 0; i < 54000; i++)
            {
                poker.Shuffle();
                for (int j = 0; j < 6; j++)
                {
                    randomNum++;
                    Card   card = poker.GetCard();
                    string hash = card.ToString();
                    if (!_dict.ContainsKey(hash))
                    {
                        _dict.Add(hash, 0);
                    }
                    _dict[hash] += 1;
                }
            }
            string content = string.Empty;
            int    max     = int.MinValue;
            int    min     = int.MaxValue;

            foreach (string key in _dict.Keys)
            {
                content += string.Format("key:{0} count:{1}\n", key.ToCard(), _dict[key]);
                if (_dict[key] > max)
                {
                    max = _dict[key];
                }
                if (_dict[key] < min)
                {
                    min = _dict[key];
                }
            }
            int range = randomNum / 54 / 10;

            if (_dict.Count != Poker.CARD_NUM)
            {
                Console.WriteLine("生成卡牌数量错误");
                return(false);
            }
            if (max - min > range)
            {
                Console.WriteLine("生成随机数不够随机");
                return(false);
            }
            return(true);
        }
Example #2
0
        public void NewGame_PackCardCount()
        {
            Poker.NewGame();
            Assert.Equal(52, Poker.Count);

            _ = Poker.GetCard();
            Assert.Equal(51, Poker.Count);

            Poker.NewGame();
            Assert.Equal(52, Poker.Count);

            for (int i = 52; i > 0; i--)
            {
                _ = Poker.GetCard();
            }
            Assert.Null(Poker.GetCard());
        }