A game framework written with osu! in mind.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix Enumerable.GetPrevious() returning non-null if not in collection

+21 -3
+20
osu.Framework.Tests/Lists/TestEnumerableExtensions.cs
··· 28 28 { 29 29 Assert.AreEqual(string.Empty, Enumerable.Empty<string>().GetCommonPrefix()); 30 30 } 31 + 32 + [TestCase("a", null)] 33 + [TestCase("b", "a")] 34 + [TestCase("c", "b")] 35 + [TestCase("d", null)] 36 + public void TestGetPrevious(string item, string expected) 37 + { 38 + string[] arr = { "a", "b", "c" }; 39 + Assert.That(arr.GetPrevious(item), Is.EqualTo(expected)); 40 + } 41 + 42 + [TestCase("a", "b")] 43 + [TestCase("b", "c")] 44 + [TestCase("c", null)] 45 + [TestCase("d", null)] 46 + public void TestGetNext(string item, string expected) 47 + { 48 + string[] arr = { "a", "b", "c" }; 49 + Assert.That(arr.GetNext(item), Is.EqualTo(expected)); 50 + } 31 51 } 32 52 }
+1 -3
osu.Framework/Extensions/IEnumerableExtensions/EnumerableExtensions.cs
··· 52 52 /// <param name="pivot">The pivot value.</param> 53 53 /// <returns>The item in <paramref name="collection"/> appearing before <paramref name="pivot"/>, or null if no such item exists.</returns> 54 54 public static T GetPrevious<T>(this IEnumerable<T> collection, T pivot) 55 - { 56 - return collection.TakeWhile(i => !EqualityComparer<T>.Default.Equals(i, pivot)).LastOrDefault(); 57 - } 55 + => collection.Reverse().GetNext(pivot); 58 56 59 57 /// <summary> 60 58 /// Returns the most common prefix of every string in this <see cref="IEnumerable{T}"/>