Ejemplo n.º 1
0
        public void ListOfDoubles()
        {
            double[] values = new double[] {
                5.0, -4.0, 333.0, -0.2, 1
            };
            double[] expectedValues = new double[] {
                //  indexes = [0,1,2,3,4], so maxValue = 5 --> index at 2 returned
                333.0,
                //  indexes = [0,1,3,4], so maxValue = 4 --> index at 3 returned
                1,
                //  indexes = [0,1,3], so maxValue = 3 --> index at 0 returned
                5.0,
                //  indexes = [1,3], so maxValue = 2 --> index at 1 returned
                -0.2,
                //  indexes = [1], so maxValue = 1 --> index at 0 returned
                -4.0
            };

            Generic.IList <double> list         = new Generic.List <double>(values);
            Generic.IList <double> shuffledList = List.Shuffle(list,
                                                               randomNumGen);
            Assert.AreEqual(expectedValues.Length, shuffledList.Count);
            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], shuffledList[i]);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a copy of a list with the items in random order.
        /// </summary>
        /// <param name="list">
        /// The list to copy.
        /// </param>
        /// <param name="randNumGen">
        /// An object that generates random numbers.
        /// </param>
        /// <returns>
        /// A copy of the list with its items shuffled (their order in the
        /// list is random).
        /// </returns>
        public static Generic.IList <T> Shuffle <T>(Generic.IList <T> list,
                                                    System.Random randomNumGen)
        {
            if (list == null)
            {
                return(null);
            }
            Require.ArgumentNotNull(randomNumGen);

            //  List of item indexes.
            Generic.List <int> indexes = new Generic.List <int>(list.Count);
            for (int i = 0; i < list.Count; ++i)
            {
                indexes.Add(i);
            }

            Generic.List <T> shuffledList = new Generic.List <T>(list.Count);
            while (indexes.Count > 0)
            {
                //  Randomly pick a remaining item in the list
                int indexOfIndex = randomNumGen.Next(indexes.Count);
                int index        = indexes[indexOfIndex];
                indexes.RemoveAt(indexOfIndex);
                shuffledList.Add(list[index]);
            }

            return(shuffledList);
        }
        public Utilities(string url, string userName, string password)
        {
            context = new ClientContext(url);
            SecureString securePassword = new SecureString();

            Array.ForEach(password.ToArray(), securePassword.AppendChar);
            context.Credentials = new SharePointOnlineCredentials(userName, securePassword);
            Logs = new Generic.List <string>();
        }