mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #5112 from jellyfin/shuffle
Add test for ShuffleExtensions
This commit is contained in:
commit
793ae6f7a6
@ -33,8 +33,7 @@ namespace MediaBrowser.Common.Extensions
|
|||||||
int n = list.Count;
|
int n = list.Count;
|
||||||
while (n > 1)
|
while (n > 1)
|
||||||
{
|
{
|
||||||
n--;
|
int k = rng.Next(n--);
|
||||||
int k = rng.Next(n + 1);
|
|
||||||
T value = list[k];
|
T value = list[k];
|
||||||
list[k] = list[n];
|
list[k] = list[n];
|
||||||
list[n] = value;
|
list[n] = value;
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using MediaBrowser.Common.Extensions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Common.Tests.Extensions
|
||||||
|
{
|
||||||
|
public static class ShuffleExtensionsTests
|
||||||
|
{
|
||||||
|
private static readonly Random _rng = new Random();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public static void Shuffle_Valid_Correct()
|
||||||
|
{
|
||||||
|
byte[] original = new byte[1 << 6];
|
||||||
|
_rng.NextBytes(original);
|
||||||
|
byte[] shuffled = (byte[])original.Clone();
|
||||||
|
shuffled.Shuffle();
|
||||||
|
|
||||||
|
Assert.NotEqual(original, shuffled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user