diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..165a5ff --- /dev/null +++ b/.appveyor.yml @@ -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%" diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..508dcc3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: csharp +solution: CSF.CollectionComparers.sln + +jobs: + include: + - dotnet: 2.2.207 + mono: latest + +script: + - dotnet build + - dotnet test diff --git a/CSF.CollectionComparers.Tests/BagEqualityComparerTests.cs b/CSF.CollectionComparers.Tests/BagEqualityComparerTests.cs index dc29d35..22e23a6 100755 --- a/CSF.CollectionComparers.Tests/BagEqualityComparerTests.cs +++ b/CSF.CollectionComparers.Tests/BagEqualityComparerTests.cs @@ -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 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 sut) { diff --git a/CSF.CollectionComparers.Tests/CSF.CollectionComparers.Tests.csproj b/CSF.CollectionComparers.Tests/CSF.CollectionComparers.Tests.csproj index 5989679..c1b281c 100644 --- a/CSF.CollectionComparers.Tests/CSF.CollectionComparers.Tests.csproj +++ b/CSF.CollectionComparers.Tests/CSF.CollectionComparers.Tests.csproj @@ -3,7 +3,7 @@ netcoreapp2.2 true - 1.1.0 + 1.1.1 diff --git a/CSF.CollectionComparers.sln b/CSF.CollectionComparers.sln index 327875e..c5f8475 100644 --- a/CSF.CollectionComparers.sln +++ b/CSF.CollectionComparers.sln @@ -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}" @@ -161,6 +163,6 @@ Global $25.NamingStyle = PascalCase $25.IncludeInstanceMembers = True $25.IncludeStaticEntities = True - version = 1.1.0 + version = 1.1.1 EndGlobalSection EndGlobal diff --git a/CSF.CollectionComparers/BagEqualityComparer.cs b/CSF.CollectionComparers/BagEqualityComparer.cs index 47bd3d8..224ba1d 100755 --- a/CSF.CollectionComparers/BagEqualityComparer.cs +++ b/CSF.CollectionComparers/BagEqualityComparer.cs @@ -157,12 +157,24 @@ public int GetHashCode(IEnumerable obj) /// public BagEqualityComparer() : this(null, null) {} + /// + /// Initializes a new instance of the class. + /// + /// An equality comparer by which to compare items within collections. + public BagEqualityComparer(IEqualityComparer itemEqComparer) : this(itemEqComparer, null) { } + + /// + /// Initializes a new instance of the class. + /// + /// An item comparer used to determine an order of items within collections. + public BagEqualityComparer(IComparer itemComparer) : this(null, itemComparer) { } + /// /// Initializes a new instance of the class. /// /// An equality comparer by which to compare items within collections. /// An item comparer used to determine an order of items within collections. - public BagEqualityComparer(IEqualityComparer itemEqComparer = null, IComparer itemComparer = null) + public BagEqualityComparer(IEqualityComparer itemEqComparer, IComparer itemComparer) { this.itemEqComparer = itemEqComparer ?? EqualityComparer.Default; this.itemComparer = itemComparer ?? Comparer.Default; diff --git a/CSF.CollectionComparers/CSF.CollectionComparers.csproj b/CSF.CollectionComparers/CSF.CollectionComparers.csproj index 8be2ca0..4b27178 100644 --- a/CSF.CollectionComparers/CSF.CollectionComparers.csproj +++ b/CSF.CollectionComparers/CSF.CollectionComparers.csproj @@ -9,7 +9,7 @@ Implementations of the generic IEqualityComparer<T> which are used for comparing generic IEnumerable<T> 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. - 1.1.0 + 1.1.1 $(ReleaseVersion) $(ReleaseVersion) MIT diff --git a/Tools/EnableMultiTargetingWithMono.targets b/Tools/EnableMultiTargetingWithMono.targets new file mode 100644 index 0000000..b23c4a8 --- /dev/null +++ b/Tools/EnableMultiTargetingWithMono.targets @@ -0,0 +1,23 @@ + + + + + + /Library/Frameworks/Mono.framework/Versions/Current/lib/mono + /usr/lib/mono + /usr/local/lib/mono + + $(BaseFrameworkPathOverrideForMono)/4.0-api + $(BaseFrameworkPathOverrideForMono)/4.5-api + $(BaseFrameworkPathOverrideForMono)/4.5.1-api + $(BaseFrameworkPathOverrideForMono)/4.5.2-api + $(BaseFrameworkPathOverrideForMono)/4.6-api + $(BaseFrameworkPathOverrideForMono)/4.6.1-api + $(BaseFrameworkPathOverrideForMono)/4.6.2-api + $(BaseFrameworkPathOverrideForMono)/4.7-api + $(BaseFrameworkPathOverrideForMono)/4.7.1-api + true + + $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) + +