Esempio n. 1
0
        public void FromRandomMoves2ExceptionTest()
        {
            Random random = new Random(7777777);
            int    length = 50;

            double[] probabilities = Enumerable
                                     .Repeat(1d, 18)
                                     .ToArray();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => Alg.FromRandomMoves(-1, random, probabilities));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.FromRandomMoves(length, null, probabilities));
            Assert.ThrowsException <ArgumentNullException>(() => Alg.FromRandomMoves(length, random, null));

            //negative probability value
            probabilities[7] = -1;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(length, random, probabilities));

            //all probability values zero
            probabilities = Enumerable
                            .Repeat(0d, 18)
                            .ToArray();

            Alg lengthZero = Alg.FromRandomMoves(0, random, probabilities);

            Assert.AreEqual(0, lengthZero.Length);

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(1, random, probabilities));

            //one probability value non-zero
            probabilities[7] = 1d;

            Alg lengthOne = Alg.FromRandomMoves(1, random, probabilities);

            Assert.AreEqual(Alg.FromString("F2"), lengthOne);

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(2, random, probabilities));

            //two probability values non-zero
            probabilities[8] = 1d;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(2, random, probabilities));

            probabilities[8]  = 0d;
            probabilities[15] = 1d;

            Alg lengthTwo = Alg.FromRandomMoves(2, random, probabilities);

            CollectionAssert.AreEquivalent(Alg.FromString("F2 B").ToArray(), lengthTwo.ToArray());

            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(3, random, probabilities));

            //three probability values non-zero
            probabilities[8] = 1d;
            Assert.ThrowsException <ArgumentException>(() => Alg.FromRandomMoves(3, random, probabilities));

            probabilities[8] = 0d;
            probabilities[0] = 1d;

            Alg lengthThree = Alg.FromRandomMoves(3, random, probabilities);

            Assert.IsTrue(lengthThree.Contains(Move.R1));
        }