public void ShuffleMultipleAndCompare() { IShuffler<int> shuffler = new FisherYatesModernShuffler<int>(); var shuffledLists = new List<IList<int>>(); for (int i = 0; i < 1000; i++) { var list = GetListOfIntegers(); shuffler.Shuffle(list); shuffledLists.Add(list); } // filter the lists for only unique lists // if the number of unique lists match the number of lists shuffled // then all of the lists have been shuffled var uniqueLists = shuffledLists.Distinct(); Assert.Equal(shuffledLists.Count(), uniqueLists.Count()); // add one of the lists a second time to make sure our check is valid // as a sanity check shuffledLists.Add(shuffledLists.First()); uniqueLists = shuffledLists.Distinct(); Assert.NotEqual(shuffledLists.Count(), uniqueLists.Count()); }
public void ShuffleListOfIntegers() { IList<int> control = GetListOfIntegers(); IList<int> toBeShuffled = GetListOfIntegers(); IShuffler<int> shuffler = new FisherYatesModernShuffler<int>(); shuffler.Shuffle(toBeShuffled); // ensure we didn't lose anyone on the way :) Assert.Equal(control.Count, toBeShuffled.Count); int numberInSamePosition = 0; for (int i = 0; i < toBeShuffled.Count; i++) { if (control[i] == toBeShuffled[i]) { numberInSamePosition++; } } Assert.Equal(0, numberInSamePosition); }