Skip to content

Commit

Permalink
Minor fixes (#104)
Browse files Browse the repository at this point in the history
* Fix overload resolution on array.Reverse()
* Update packages
* Fix indexed item equality comparison (item index was ignored).
  • Loading branch information
ig-sinicyn authored Feb 17, 2020
1 parent 4ef60df commit f91ab23
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
12 changes: 6 additions & 6 deletions CodeJam.Blocks.Tests/CodeJam.Blocks.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' AND '$(TargetFramework)' != 'netcoreapp1.1' ">
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
<!-- NUnit v3.11 is the last version supporting .NET 2.0 -->
<PackageReference Include="NUnit" Version="[3.11.0]" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<!-- NUnit v3.9 is the last version supporting .NET Core 1.0 -->
<PackageReference Include="NUnit" Version="[3.9.0]" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<!-- Microsoft.NET.Test.Sdk v16.3 is the last version supporting .NET Core 1.0 -->
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<!-- Microsoft.NET.Test.Sdk v16.2 is the last version supporting .NET Core 1.0 -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[16.2.0]" />
</ItemGroup>
<!-- #endregion -->
Expand Down
4 changes: 2 additions & 2 deletions CodeJam.Experimental.Tests/CodeJam.Experimental.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 6 additions & 9 deletions CodeJam.Main.Tests/CodeJam.Main.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net20' AND '$(TargetFramework)' != 'netcoreapp1.1' ">
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net20' ">
<!-- NUnit v3.11 is the last version supporting .NET 2.0 -->
<PackageReference Include="NUnit" Version="[3.11.0]" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<!-- NUnit v3.9 is the last version supporting .NET Core 1.0 -->
<PackageReference Include="NUnit" Version="[3.9.0]" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<!-- Microsoft.NET.Test.Sdk v16.3 is the last version supporting .NET Core 1.0 -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[16.2.0]" />
</ItemGroup>
<!-- #endregion -->

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
</ItemGroup>
<!-- #endregion -->

<ItemGroup>
<ProjectReference Include="..\CodeJam.Main\CodeJam.Main.csproj" />
Expand Down
22 changes: 22 additions & 0 deletions CodeJam.Main.Tests/OverloadResolutionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Linq;

using CodeJam.Collections;

using NUnit.Framework;

// ReSharper disable once CheckNamespace
namespace CodeJam
{
[TestFixture(Category = "Compatibility")]
public static class OverloadResolutionsTests
{
[Test]
public static void ArrayResolutionTests()
{
var a = new[] { 1, 2, 3 };
a.Reverse();
Assert.AreEqual(a, new[] { 3, 2, 1 });
}
}
}
6 changes: 4 additions & 2 deletions CodeJam.Main/Collections/Array/ArrayExtensions.Infix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,19 @@ public static int LastIndexOf<T>([NotNull] this T[] array, T value, int startInd

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

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

#region Sort
/// <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>
Expand Down
9 changes: 7 additions & 2 deletions CodeJam.Main/Collections/Enumerable/IndexedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public void Deconstruct(out int index, out T item, out bool isFirst, out bool is
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(IndexedItem<T> other) => EqualityComparer<T>.Default.Equals(Item, other.Item);
public bool Equals(IndexedItem<T> other) =>
EqualityComparer<T>.Default.Equals(Item, other.Item) &&
Index == other.Index;

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

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

/// <summary>
/// Operator ==
Expand Down

0 comments on commit f91ab23

Please sign in to comment.