Example #1
0
        public static void TestChooseRandom()
        {
            const int    NUM_SELECTIONS = 1000;
            CommandQueue queue          = new CommandQueue();

            int[] selections = new int[NUM_SELECTIONS];
            int   i          = 0;

            queue.Enqueue(
                Cmd.Repeat(NUM_SELECTIONS,
                           Cmd.Do(() => selections[i] = 0),
                           Cmd.ChooseRandom(
                               Cmd.Do(() => selections[i] = 1),
                               Cmd.Do(() => selections[i] = 2),
                               Cmd.Do(() => selections[i] = 3),
                               Cmd.Do(() => selections[i] = 4),
                               Cmd.Do(() => selections[i] = 5),
                               Cmd.Do(() => selections[i] = 6),
                               Cmd.Do(() => selections[i] = 7),
                               Cmd.Do(() => selections[i] = 8),
                               Cmd.Do(() => selections[i] = 9),
                               null
                               ),
                           Cmd.Do(() => i++)
                           )
                );

            queue.Update(1.0f);

            // The chance of every number being the same is 1 / 10 ^ (NUM_SELECTIONS - 1).
            bool allEqual = true;

            for (int c = 0; c < NUM_SELECTIONS - 1; c++)
            {
                if (selections[c] != selections[c + 1])
                {
                    allEqual = false;
                    break;
                }
            }

            Assert.IsTrue(!allEqual, "All numbers were equal, this is either extremely unlikely, or a bug.");
        }