Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 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);
        }