Beispiel #1
0
        public void GetRandomItemReturnsUnequallyProbableItemsWithExpectedProbability()
        {
            var items         = new[] { "Moat", "Smithy", "Village", "Market" };
            var randomNumbers = new[] { 0, 1, 2, 3, 4 };

            var distribution = new ProbabilityDistribution(new RandomNumberProviderStub(randomNumbers), items);

            distribution.IncreaseLikelihood("Village");
            var occurances = new Dictionary <string, int>();

            foreach (var item in items)
            {
                occurances[item] = 0;
            }

            for (int i = 0; i < randomNumbers.Length; i++)
            {
                occurances[distribution.RandomItem(items)]++;
            }

            var expected = new Dictionary <string, int>
            {
                { "Moat", 1 },
                { "Smithy", 1 },
                { "Village", 2 },
                { "Market", 1 }
            };

            CollectionAssert.AreEquivalent(expected, occurances);
        }
        public void GetRandomItemReturnsUnequallyProbableItemsWithExpectedProbability()
        {
            var items = new[] { "Moat", "Smithy", "Village", "Market" };
            var randomNumbers = new[] { 0, 1, 2, 3, 4 };

            var distribution = new ProbabilityDistribution(new RandomNumberProviderStub(randomNumbers), items);
            distribution.IncreaseLikelihood("Village");
            var occurances = new Dictionary<string, int>();

            foreach (var item in items)
                occurances[item] = 0;

            for (int i = 0; i < randomNumbers.Length; i++)
                occurances[distribution.RandomItem(items)]++;

            var expected = new Dictionary<string, int>
            {
                {"Moat", 1},
                {"Smithy", 1},
                {"Village", 2},
                {"Market", 1}
            };

            CollectionAssert.AreEquivalent(expected, occurances);
        }