public void WhenAddingItemsWhileShuffled_OrderIsSameAsBeforeButWithExtraItem() { var arr = new[] { new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile() }; Console.WriteLine("Original: {0}", string.Join(",", arr.Select(x => x.Id))); var queue = new MediaQueue(); Console.WriteLine("Current Index: {0}", queue.Index); queue.AddRange(arr); queue.ToggleShuffle(); queue.Add(new MediaFile()); Console.WriteLine("Shuffled: {0}", string.Join(",", queue.Cast <MediaFile>().Select(x => x.Id))); queue.ToggleShuffle(); Console.WriteLine("Unshuffled: {0}", string.Join(",", queue.Cast <MediaFile>().Select(x => x.Id))); CollectionAssert.AllItemsAreUnique(queue.Cast <MediaFile>().Select(x => x.Id)); Assert.AreEqual(arr[0].Id, queue.Cast <MediaFile>().ElementAt(0).Id); Assert.AreEqual(arr[1].Id, queue.Cast <MediaFile>().ElementAt(1).Id); Assert.AreEqual(arr[2].Id, queue.Cast <MediaFile>().ElementAt(2).Id); Assert.AreEqual(arr[3].Id, queue.Cast <MediaFile>().ElementAt(3).Id); Assert.AreEqual(arr[4].Id, queue.Cast <MediaFile>().ElementAt(4).Id); Assert.AreEqual(arr[5].Id, queue.Cast <MediaFile>().ElementAt(5).Id); Assert.AreEqual(arr[6].Id, queue.Cast <MediaFile>().ElementAt(6).Id); Assert.AreEqual(arr[7].Id, queue.Cast <MediaFile>().ElementAt(7).Id); Assert.AreEqual(arr[8].Id, queue.Cast <MediaFile>().ElementAt(8).Id); Assert.AreEqual(arr[9].Id, queue.Cast <MediaFile>().ElementAt(9).Id); Assert.AreEqual(arr[10].Id, queue.Cast <MediaFile>().ElementAt(10).Id); Assert.AreEqual(99, queue.Cast <MediaFile>().Last().Id); Assert.AreEqual(arr.Length + 1, queue.Count, "The array length is different"); }
public void WhenShufflingWorks_OrderIsRandomized() { var arr = new[] { new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile() }; Console.WriteLine("Original: {0}", string.Join(",", arr.Select(x => x.Id))); var queue = new MediaQueue(); Console.WriteLine("Current Index: {0}", queue.Index); queue.AddRange(arr); queue.ToggleShuffle(); Console.WriteLine("Result: {0}", string.Join(",", queue.Cast <MediaFile>().Select(x => x.Id))); CollectionAssert.AllItemsAreUnique(queue.Cast <MediaFile>().Select(x => x.Id)); CollectionAssert.AreEquivalent(queue.Cast <MediaFile>().Select(x => x.Id), arr.Select(x => x.Id)); Assert.That(queue.Cast <MediaFile>().Select(x => x.Id), Is.Not.Ordered); Assert.AreEqual(arr[queue.Index].Id, queue.Cast <MediaFile>().ElementAt(queue.Index).Id, "The current item has been moved"); Assert.AreEqual(arr.Length, queue.Count, "The array length is different"); }
public void ShuffleTwice_WhenRandomNumberGeneratorWorks_OrderIsDifferent() { var arr = new[] { new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile(), new MediaFile() }; Console.WriteLine("Original: {0}", string.Join(",", arr.Select(x => x.Id))); var queue1 = new MediaQueue(); queue1.AddRange(arr); var queue2 = new MediaQueue(); queue2.AddRange(arr); // Randomize in quick succession to prove that the result is not the same // Using Random() here would create two equal lists, hence the use of PCLCrypto. queue1.ToggleShuffle(); queue2.ToggleShuffle(); Console.WriteLine("Queue1: {0}", string.Join(",", queue1.Cast <MediaFile>().Select(x => x.Id))); Console.WriteLine("Queue2: {0}", string.Join(",", queue2.Cast <MediaFile>().Select(x => x.Id))); CollectionAssert.AllItemsAreUnique(queue1.Cast <MediaFile>().Select(x => x.Id)); CollectionAssert.AllItemsAreUnique(queue2.Cast <MediaFile>().Select(x => x.Id)); CollectionAssert.AreNotEqual(queue1.Cast <MediaFile>().Select(x => x.Id), queue2.Cast <MediaFile>().Select(x => x.Id)); Assert.AreEqual(arr[queue1.Index].Id, queue1.Cast <MediaFile>().ElementAt(queue1.Index).Id, "The current item has been moved"); Assert.AreEqual(arr[queue2.Index].Id, queue2.Cast <MediaFile>().ElementAt(queue2.Index).Id, "The current item has been moved"); }
public void ShuffledAndRepeated() { var queue = new MediaQueue(); var tracks = new[] { new MediaFile(), new MediaFile(), }; queue.AddRange(tracks); queue.ToggleShuffle(); queue.ToggleRepeat(RepeatType.RepeatOne); IList <NotifyCollectionChangedEventArgs> collectionChangedEvents = new List <NotifyCollectionChangedEventArgs>(); IList <PropertyChangedEventArgs> propertyChangedEvents = new List <PropertyChangedEventArgs>(); queue.CollectionChanged += (sender, e) => collectionChangedEvents.Add(e); queue.PropertyChanged += (sender, e) => propertyChangedEvents.Add(e); queue.Clear(); Assert.AreEqual(0, queue.Count); Assert.AreEqual(null, queue.Current); Assert.AreEqual(-1, queue.Index); Assert.AreEqual(RepeatType.RepeatOne, queue.Repeat); Assert.AreEqual(RepeatType.None, queue.Shuffle); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Current").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Index").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Count").Count()); Assert.AreEqual(1, propertyChangedEvents.Where(e => e.PropertyName == "Shuffle").Count()); Assert.AreEqual(4, propertyChangedEvents.Count); Assert.AreEqual(1, collectionChangedEvents.Where(e => e.NewItems == null && e.OldItems == null).Count()); Assert.AreEqual(1, collectionChangedEvents.Count); }