/// <summary>
        /// Generate a random enum value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentException">T must be an enumerated type</exception>
        public static T NextEnum <T>() where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum)
            {
                throw new ArgumentException("T must be an enumerated type");
            }
            Type etype = typeof(T);

            T[] vals = etype.GetEnumValues().Cast <T>().ToArray();
            return(RandomArray.Pick(vals));
        }
Example #2
0
        public void TestPick()
        {
            int[] listEmpty = { };
            int   value     = RandomArray.Pick(listEmpty);

            Assert.True(value == 0);

            int[] array = { 1, 2 };
            value = RandomArray.Pick(array);
            Assert.True(value == 1 || value == 2);

            List <int> list = new List <int>();

            Assert.Equal(0, RandomArray.Pick(list));

            list.Add(1);
            list.Add(2);
            value = RandomArray.Pick(array);
            Assert.True(value == 1 || value == 2);
        }