From 80e22d9670f3ea8b722e1e57bc73529a5c652b25 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 26 Jan 2021 20:21:07 +0100 Subject: [PATCH 1/2] Add test for ShuffleExtensions --- .../Extensions/ShuffleExtensionsTests.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/Jellyfin.Common.Tests/Extensions/ShuffleExtensionsTests.cs diff --git a/tests/Jellyfin.Common.Tests/Extensions/ShuffleExtensionsTests.cs b/tests/Jellyfin.Common.Tests/Extensions/ShuffleExtensionsTests.cs new file mode 100644 index 000000000..cbdbcf112 --- /dev/null +++ b/tests/Jellyfin.Common.Tests/Extensions/ShuffleExtensionsTests.cs @@ -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); + } + } +} From bf4829a38ce6b393c2bbab258c4a7ebe5ee33aba Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 26 Jan 2021 20:28:35 +0100 Subject: [PATCH 2/2] Remove redundant statement --- MediaBrowser.Common/Extensions/ShuffleExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs index 459bec110..6f0ea9bd5 100644 --- a/MediaBrowser.Common/Extensions/ShuffleExtensions.cs +++ b/MediaBrowser.Common/Extensions/ShuffleExtensions.cs @@ -33,8 +33,7 @@ namespace MediaBrowser.Common.Extensions int n = list.Count; while (n > 1) { - n--; - int k = rng.Next(n + 1); + int k = rng.Next(n--); T value = list[k]; list[k] = list[n]; list[n] = value;