Exemplo n.º 1
0
        public void FailsWhenFirstArgIsNull()
        {
            var rng             = new Random();
            IEnumerable <int> a = null;

            Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleCopy(a, rng));
        }
Exemplo n.º 2
0
        public void FailsWhenFirstArgIsNull()
        {
            var         rng = new Random();
            IList <int> a   = null;

            Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleInPlace(a, rng));
        }
Exemplo n.º 3
0
        public void FailsWhenSecondArgIsNull()
        {
            Random rng = null;
            var    a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            Assert.Throws <ArgumentNullException>(() => ShuffleOps.ShuffleInPlace(a, rng));
        }
Exemplo n.º 4
0
        public void ReadmeExampleWorks()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            ShuffleOps.ShuffleInPlace(a, rng);
            Assert.Equal(new[] { 6, 1, 4, 5, 2, 3 }, a);
        }
Exemplo n.º 5
0
        public void Works()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };
            var b = ShuffleOps.ShuffleCopy(a, rng);

            Assert.Equal(new[] { 6, 1, 4, 5, 2, 3 }, b);
        }
Exemplo n.º 6
0
        private static void Example2()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };
            var b = ShuffleOps.ShuffleCopy(a, rng);

            Console.WriteLine(string.Join(", ", b));
        }
Exemplo n.º 7
0
        private static void Example1()
        {
            var rng = new Random(Seed: 5);
            var a   = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            ShuffleOps.ShuffleInPlace(a, rng);
            Console.WriteLine(string.Join(", ", a));
        }
Exemplo n.º 8
0
        public IChromosome GenerisiRandomTestSaOblastima(List <int> oblasti, int Length)
        {
            List <Question> questionsNova = new List <Question>();
            Test            result        = null;
            Random          r             = new Random();

            do
            {
                //Bira iz banke nasumicno pitanja samo koja sadrze te oblasti
                var questionsDomain = GetQuestionsWhichContainDomains(oblasti);

                questionsNova.AddRange(ShuffleOps.ShuffleCopy <Question>(questionsDomain, r).Take(Length - questionsNova.Count));
                questionsNova = questionsNova.Distinct().ToList();

                result = new Test(questionsNova, Length);
            }while (result.HasDuplicate());

            return(result);
        }
Exemplo n.º 9
0
 /// <summary>Shuffles a <see cref="IList{T}"/>.</summary>
 /// <typeparam name="T">Type of items in <paramref name="list"/>.</typeparam>
 /// <param name="source">The random number generator to use.</param>
 /// <param name="list">The list to shuffle.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="list"/> is null - or <paramref name="source"/> is null.</exception>
 public static void Shuffle <T>(this Random source, IList <T> list)
 => ShuffleOps.ShuffleInPlace(list, source);
Exemplo n.º 10
0
 /// <summary>Returns a shuffled array of an <see cref="IEnumerable{T}"/>.</summary>
 /// <typeparam name="T">Type of items in <paramref name="source"/>.</typeparam>
 /// <param name="source">The enumerable to shuffle.</param>
 /// <param name="randomNumberGenerator">The random number generator to use.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="source"/> is null - or <paramref name="randomNumberGenerator"/> is null.</exception>
 public static T[] ShuffleCopy <T>(this IEnumerable <T> source, Random randomNumberGenerator)
 => ShuffleOps.ShuffleCopy(source, randomNumberGenerator);