|
|
|
|
@ -15,6 +15,54 @@ namespace ErsatzTV.Core.Tests.Scheduling
@@ -15,6 +15,54 @@ namespace ErsatzTV.Core.Tests.Scheduling
|
|
|
|
|
// this seed will produce (shuffle) 1-10 in order
|
|
|
|
|
private const int MagicSeed = 670596; |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Episodes_Should_Not_Duplicate_When_Reshuffling() |
|
|
|
|
{ |
|
|
|
|
List<MediaItem> contents = Episodes(10); |
|
|
|
|
|
|
|
|
|
// normally returns 10 5 7 4 3 6 2 8 9 1 1 (note duplicate 1 at end)
|
|
|
|
|
var state = new CollectionEnumeratorState { Seed = 8 }; |
|
|
|
|
|
|
|
|
|
var shuffledContent = new ShuffledMediaCollectionEnumerator(contents, state); |
|
|
|
|
|
|
|
|
|
var list = new List<int>(); |
|
|
|
|
for (var i = 1; i <= 1000; i++) |
|
|
|
|
{ |
|
|
|
|
shuffledContent.Current.IsSome.Should().BeTrue(); |
|
|
|
|
shuffledContent.Current.Do(x => list.Add(x.Id)); |
|
|
|
|
shuffledContent.MoveNext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (var i = 0; i < list.Count - 1; i++) |
|
|
|
|
{ |
|
|
|
|
if (list[i] == list[i + 1]) |
|
|
|
|
{ |
|
|
|
|
Assert.Fail("List contains duplicate items"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
[Timeout(2000)] |
|
|
|
|
public void Duplicate_Check_Should_Ignore_Single_Item() |
|
|
|
|
{ |
|
|
|
|
List<MediaItem> contents = Episodes(1); |
|
|
|
|
|
|
|
|
|
var state = new CollectionEnumeratorState(); |
|
|
|
|
|
|
|
|
|
var shuffledContent = new ShuffledMediaCollectionEnumerator(contents, state); |
|
|
|
|
|
|
|
|
|
var list = new List<int>(); |
|
|
|
|
for (var i = 1; i <= 10; i++) |
|
|
|
|
{ |
|
|
|
|
shuffledContent.Current.IsSome.Should().BeTrue(); |
|
|
|
|
shuffledContent.Current.Do(x => list.Add(x.Id)); |
|
|
|
|
shuffledContent.MoveNext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
list.Should().Equal(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Episodes_Should_Shuffle() |
|
|
|
|
{ |
|
|
|
|
|