Skip to content

Commit

Permalink
Merge branch 'release/1.1.1' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfowler committed Apr 4, 2020
2 parents a4efd51 + 33de5ef commit b2efc18
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 6 deletions.
23 changes: 23 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '{branch}-{build}'
image: Visual Studio 2017

init:
- cmd: git config --global core.autocrlf true

install:
- cmd: git submodule update --init --recursive
- cmd: dotnet tool install --global dotnet-sonarscanner

before_build:
- cmd: dotnet --version
- cmd: dotnet restore --verbosity m
- cmd: dotnet-sonarscanner begin /k:"CSF.CollectionComparers" /v:AppVeyor_build_%APPVEYOR_BUILD_NUMBER% /o:craigfowler-github /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=%SONARCLOUD_SECRET_KEY% /d:sonar.cs.nunit.reportsPaths=%APPVEYOR_BUILD_FOLDER%\CSF.CollectionComparers.Tests\TestResults\TestResults.xml /d:sonar.cs.opencover.reportsPaths=%APPVEYOR_BUILD_FOLDER%\CSF.CollectionComparers.Tests\TestResults\coverage.opencover.xml

build_script:
- cmd: dotnet build

test_script:
- cmd: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=\"json,opencover\" /p:CoverletOutput=\"TestResults/\" --test-adapter-path:. --logger:\"nunit\"

after_test:
- cmd: dotnet-sonarscanner end /d:"sonar.login=%SONARCLOUD_SECRET_KEY%"
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: csharp
solution: CSF.CollectionComparers.sln

jobs:
include:
- dotnet: 2.2.207
mono: latest

script:
- dotnet build
- dotnet test
16 changes: 16 additions & 0 deletions CSF.CollectionComparers.Tests/BagEqualityComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ public void GetHashCode_returns_different_values_for_two_collections_with_same_e
Assert.That(result1, Is.Not.EqualTo(result2));
}

[Test, AutoMoqData]
public void GetHashCode_should_not_return_same_value_for_a_collection_with_an_even_count_of_item_differences(BagEqualityComparer<string> sut)
{
// Reproduces issue #1
//
// The item "two" appears three times in the first collection and once in the second,
// thus the number of differences between the counts of that item's appearance is an even number: 2
var collectionOne = new[] { "one", "two", "two", "three", "two" };
var collectionTwo = new[] { "one", "three", "two" };

var result1 = sut.GetHashCode(collectionOne);
var result2 = sut.GetHashCode(collectionTwo);

Assert.That(result1, Is.Not.EqualTo(result2));
}

[Test, AutoMoqData]
public void GetHashCode_returns_different_value_for_two_collections_with_different_elements(BagEqualityComparer<string> sut)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsTestProject>true</IsTestProject>
<ReleaseVersion>1.1.0</ReleaseVersion>
<ReleaseVersion>1.1.1</ReleaseVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 5 additions & 3 deletions CSF.CollectionComparers.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010
# Visual Studio 15
VisualStudioVersion = 15.0.28307.489
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSF.CollectionComparers", "CSF.CollectionComparers\CSF.CollectionComparers.csproj", "{A7339D98-0F8B-4EA2-B3E6-9EA4104E51F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSF.CollectionComparers.Tests", "CSF.CollectionComparers.Tests\CSF.CollectionComparers.Tests.csproj", "{C4D2C6EC-1E17-46BE-B617-B56DD0FD2AF9}"
Expand Down Expand Up @@ -161,6 +163,6 @@ Global
$25.NamingStyle = PascalCase
$25.IncludeInstanceMembers = True
$25.IncludeStaticEntities = True
version = 1.1.0
version = 1.1.1
EndGlobalSection
EndGlobal
14 changes: 13 additions & 1 deletion CSF.CollectionComparers/BagEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,24 @@ public int GetHashCode(IEnumerable<TItem> obj)
/// </summary>
public BagEqualityComparer() : this(null, null) {}

/// <summary>
/// Initializes a new instance of the <see cref="BagEqualityComparer{T}"/> class.
/// </summary>
/// <param name="itemEqComparer">An equality comparer by which to compare items within collections.</param>
public BagEqualityComparer(IEqualityComparer<TItem> itemEqComparer) : this(itemEqComparer, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="BagEqualityComparer{T}"/> class.
/// </summary>
/// <param name="itemComparer">An item comparer used to determine an order of items within collections.</param>
public BagEqualityComparer(IComparer<TItem> itemComparer) : this(null, itemComparer) { }

/// <summary>
/// Initializes a new instance of the <see cref="BagEqualityComparer{T}"/> class.
/// </summary>
/// <param name="itemEqComparer">An equality comparer by which to compare items within collections.</param>
/// <param name="itemComparer">An item comparer used to determine an order of items within collections.</param>
public BagEqualityComparer(IEqualityComparer<TItem> itemEqComparer = null, IComparer<TItem> itemComparer = null)
public BagEqualityComparer(IEqualityComparer<TItem> itemEqComparer, IComparer<TItem> itemComparer)
{
this.itemEqComparer = itemEqComparer ?? EqualityComparer<TItem>.Default;
this.itemComparer = itemComparer ?? Comparer<TItem>.Default;
Expand Down
2 changes: 1 addition & 1 deletion CSF.CollectionComparers/CSF.CollectionComparers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Description>Implementations of the generic IEqualityComparer&lt;T&gt; which are used for comparing generic IEnumerable&lt;T&gt; objects. These equality comparers represent various comparison strategies such as list/sequence, set and bag equality.

In each case, effort has been made to use the "best" algorithm available for equality-testing.</Description>
<ReleaseVersion>1.1.0</ReleaseVersion>
<ReleaseVersion>1.1.1</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
23 changes: 23 additions & 0 deletions Tools/EnableMultiTargetingWithMono.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4')) and '$(OS)' == 'Unix'">
<!-- When compiling .NET SDK 2.0 projects targeting .NET 4.x on Mono using 'dotnet build' you -->
<!-- have to teach MSBuild where the Mono copy of the reference asssemblies is -->
<!-- Look in the standard install locations -->
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND EXISTS('/Library/Frameworks/Mono.framework/Versions/Current/lib/mono')">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono</BaseFrameworkPathOverrideForMono>
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND EXISTS('/usr/lib/mono')">/usr/lib/mono</BaseFrameworkPathOverrideForMono>
<BaseFrameworkPathOverrideForMono Condition="'$(BaseFrameworkPathOverrideForMono)' == '' AND EXISTS('/usr/local/lib/mono')">/usr/local/lib/mono</BaseFrameworkPathOverrideForMono>
<!-- If we found Mono reference assemblies, then use them -->
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net40'">$(BaseFrameworkPathOverrideForMono)/4.0-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net45'">$(BaseFrameworkPathOverrideForMono)/4.5-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net451'">$(BaseFrameworkPathOverrideForMono)/4.5.1-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net452'">$(BaseFrameworkPathOverrideForMono)/4.5.2-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net46'">$(BaseFrameworkPathOverrideForMono)/4.6-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net461'">$(BaseFrameworkPathOverrideForMono)/4.6.1-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net462'">$(BaseFrameworkPathOverrideForMono)/4.6.2-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net47'">$(BaseFrameworkPathOverrideForMono)/4.7-api</FrameworkPathOverride>
<FrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != '' AND '$(TargetFramework)' == 'net471'">$(BaseFrameworkPathOverrideForMono)/4.7.1-api</FrameworkPathOverride>
<EnableFrameworkPathOverride Condition="'$(BaseFrameworkPathOverrideForMono)' != ''">true</EnableFrameworkPathOverride>
<!-- Add the Facades directory. Not sure how else to do this. Necessary at least for .NET 4.5 -->
<AssemblySearchPaths Condition="'$(BaseFrameworkPathOverrideForMono)' != ''">$(FrameworkPathOverride)/Facades;$(AssemblySearchPaths)</AssemblySearchPaths>
</PropertyGroup>
</Project>

0 comments on commit b2efc18

Please sign in to comment.