Skip to content

Commit f91ab23

Browse files
authored
Minor fixes (#104)
* Fix overload resolution on array.Reverse() * Update packages * Fix indexed item equality comparison (item index was ignored).
1 parent 4ef60df commit f91ab23

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

CodeJam.Blocks.Tests/CodeJam.Blocks.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
</ItemGroup>
1919
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' AND '$(TargetFramework)' != 'netcoreapp1.1' ">
2020
<PackageReference Include="NUnit" Version="3.12.0" />
21-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
21+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
2323
</ItemGroup>
2424
<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
2525
<!-- NUnit v3.11 is the last version supporting .NET 2.0 -->
2626
<PackageReference Include="NUnit" Version="[3.11.0]" />
27-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
28-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
27+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
28+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
2929
</ItemGroup>
3030
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
3131
<!-- NUnit v3.9 is the last version supporting .NET Core 1.0 -->
3232
<PackageReference Include="NUnit" Version="[3.9.0]" />
33-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
34-
<!-- Microsoft.NET.Test.Sdk v16.3 is the last version supporting .NET Core 1.0 -->
33+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
34+
<!-- Microsoft.NET.Test.Sdk v16.2 is the last version supporting .NET Core 1.0 -->
3535
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[16.2.0]" />
3636
</ItemGroup>
3737
<!-- #endregion -->

CodeJam.Experimental.Tests/CodeJam.Experimental.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="NUnit" Version="3.12.0" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

CodeJam.Main.Tests/CodeJam.Main.Tests.csproj

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,24 @@
1919
</ItemGroup>
2020
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' AND '$(TargetFramework)' != 'netcoreapp1.1' ">
2121
<PackageReference Include="NUnit" Version="3.12.0" />
22-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
23-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
22+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
2424
</ItemGroup>
2525
<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
2626
<!-- NUnit v3.11 is the last version supporting .NET 2.0 -->
2727
<PackageReference Include="NUnit" Version="[3.11.0]" />
28-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
29-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
28+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
29+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
3030
</ItemGroup>
3131
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
3232
<!-- NUnit v3.9 is the last version supporting .NET Core 1.0 -->
3333
<PackageReference Include="NUnit" Version="[3.9.0]" />
34-
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
34+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
3535
<!-- Microsoft.NET.Test.Sdk v16.3 is the last version supporting .NET Core 1.0 -->
3636
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[16.2.0]" />
37-
</ItemGroup>
38-
<!-- #endregion -->
39-
40-
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
4137
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
4238
</ItemGroup>
39+
<!-- #endregion -->
4340

4441
<ItemGroup>
4542
<ProjectReference Include="..\CodeJam.Main\CodeJam.Main.csproj" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Linq;
3+
4+
using CodeJam.Collections;
5+
6+
using NUnit.Framework;
7+
8+
// ReSharper disable once CheckNamespace
9+
namespace CodeJam
10+
{
11+
[TestFixture(Category = "Compatibility")]
12+
public static class OverloadResolutionsTests
13+
{
14+
[Test]
15+
public static void ArrayResolutionTests()
16+
{
17+
var a = new[] { 1, 2, 3 };
18+
a.Reverse();
19+
Assert.AreEqual(a, new[] { 3, 2, 1 });
20+
}
21+
}
22+
}

CodeJam.Main/Collections/Array/ArrayExtensions.Infix.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,19 @@ public static int LastIndexOf<T>([NotNull] this T[] array, T value, int startInd
473473

474474
/// <summary>Reverses the sequence of the elements in the entire one-dimensional <see cref="Array" />.</summary>
475475
/// <param name="array">The one-dimensional <see cref="Array" /> to reverse.</param>
476+
/// <typeparam name="T">The type of the elements of the array.</typeparam>
476477
/// <exception cref="ArgumentNullException">
477478
/// <paramref name="array" /> is null. </exception>
478479
/// <exception cref="RankException">
479480
/// <paramref name="array" /> is multidimensional. </exception>
480481
/// <filterpriority>1</filterpriority>
481-
public static void Reverse([NotNull] this Array array) => Array.Reverse(array);
482+
public static void Reverse<T>([NotNull] this T[] array) => Array.Reverse(array);
482483

483484
/// <summary>Reverses the sequence of the elements in a range of elements in the one-dimensional <see cref="Array" />.</summary>
484485
/// <param name="array">The one-dimensional <see cref="Array" /> to reverse.</param>
485486
/// <param name="index">The starting index of the section to reverse.</param>
486487
/// <param name="length">The number of elements in the section to reverse.</param>
488+
/// <typeparam name="T">The type of the elements of the array.</typeparam>
487489
/// <exception cref="ArgumentNullException">
488490
/// <paramref name="array" /> is null.</exception>
489491
/// <exception cref="RankException">
@@ -493,7 +495,7 @@ public static int LastIndexOf<T>([NotNull] this T[] array, T value, int startInd
493495
/// <exception cref="ArgumentException">
494496
/// <paramref name="index" /> and <paramref name="length" /> do not specify a valid range in <paramref name="array" />.</exception>
495497
/// <filterpriority>1</filterpriority>
496-
public static void Reverse([NotNull] this Array array, int index, int length) => Array.Reverse(array, index, length);
498+
public static void Reverse<T>([NotNull] this T[] array, int index, int length) => Array.Reverse(array, index, length);
497499

498500
#region Sort
499501
/// <summary>Sorts the elements in an entire <see cref="Array" /> using the <see cref="IComparable{T}" /> generic interface implementation of each element of the <see cref="Array" />.</summary>

CodeJam.Main/Collections/Enumerable/IndexedItem.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public void Deconstruct(out int index, out T item, out bool isFirst, out bool is
104104
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
105105
/// </returns>
106106
/// <param name="other">An object to compare with this object.</param>
107-
public bool Equals(IndexedItem<T> other) => EqualityComparer<T>.Default.Equals(Item, other.Item);
107+
public bool Equals(IndexedItem<T> other) =>
108+
EqualityComparer<T>.Default.Equals(Item, other.Item) &&
109+
Index == other.Index;
108110

109111
/// <summary>Indicates whether this instance and a specified object are equal.</summary>
110112
/// <returns>
@@ -115,7 +117,10 @@ public void Deconstruct(out int index, out T item, out bool isFirst, out bool is
115117

116118
/// <summary>Returns the hash code for this instance.</summary>
117119
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
118-
public override int GetHashCode() => EqualityComparer<T>.Default.GetHashCode(Item);
120+
public override int GetHashCode() =>
121+
HashCode.Combine(
122+
EqualityComparer<T>.Default.GetHashCode(Item),
123+
Index.GetHashCode());
119124

120125
/// <summary>
121126
/// Operator ==

0 commit comments

Comments
 (0)