private Card FindBestMatch(ulong needle, List <Card> referenceCards, SetFilter fromSet, List <Card> ignoreCards) { Card bestMatch = null; var lowestHamming = int.MaxValue; var phash = new pHash(); var setComparer = new SetEqualityComparer(); foreach (var referenceCard in referenceCards) { if (fromSet != SetFilter.All && !setComparer.Equals(referenceCard.Set, fromSet.Set)) { continue; } if (ignoreCards.Any() && ignoreCards.Contains(referenceCard)) { continue; } var hamming = phash.HammingDistance(referenceCard.pHash, needle); if (hamming < lowestHamming) { lowestHamming = hamming; bestMatch = referenceCard; } } return(bestMatch); }
public void Equals_returns_true_for_two_collections_which_are_equal(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "two", "three" }; Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True); }
public void GetHashCode_ForSameObjects_ResultsAreEqual(string xString) { var uut = new SetEqualityComparer <string>();; var x = MakeTestSet(xString); uut.GetHashCode(x).ShouldBe(uut.GetHashCode(x)); }
public void Equals_returns_result_respecting_alternative_item_equality_comparer() { var sut = new SetEqualityComparer <string>(StringComparer.InvariantCultureIgnoreCase); var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "two", "THREE" }; Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True); }
public void Equals_XIsNotEquivalentToY_ReturnsFalse(string xString, string yString) { var uut = new SetEqualityComparer <string>();; var x = MakeTestSet(xString); var y = MakeTestSet(yString); uut.Equals(x, y).ShouldBeFalse(); }
public void Equals_XIsSameAsY_ReturnsTrue(string xString) { var uut = new SetEqualityComparer <string>();; var x = MakeTestSet(xString); var y = x; uut.Equals(x, y).ShouldBeTrue(); }
public void GetHashCode_ForInequivalentSets_ResultsAreNotEqual(string xString, string yString) { var uut = new SetEqualityComparer <string>();; var x = MakeTestSet(xString); var y = MakeTestSet(yString); uut.GetHashCode(x).ShouldNotBe(uut.GetHashCode(y)); }
public void GetHashCode_returns_same_value_for_collections_respecting_alternative_item_equality_comparer() { var sut = new SetEqualityComparer <string>(StringComparer.InvariantCultureIgnoreCase); var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "two", "THREE" }; var result1 = sut.GetHashCode(collectionOne); var result2 = sut.GetHashCode(collectionTwo); Assert.That(result1, Is.EqualTo(result2)); }
public void GetHashCode_SetIsNull_ThrowsException() { var uut = new SetEqualityComparer <string>();; var set = (ISet <string>)null; var result = Should.Throw <ArgumentNullException>(() => { uut.GetHashCode(set); }); result.ParamName.ShouldBe(nameof(set)); }
public void GetHashCode_does_not_pass_null_items_to_equality_comparer_hash_code_method(IEqualityComparer <string> comparer) { var sut = new SetEqualityComparer <string>(comparer); Mock.Get(comparer) .Setup(x => x.GetHashCode(It.IsAny <string>())) .Returns(1); var collection = new[] { "one", null, "three" }; sut.GetHashCode(collection); Mock.Get(comparer) .Verify(x => x.GetHashCode(null), Times.Never); }
internal ReadOnlySet(ISet <T> set, SetEqualityComparer <T> structuralEqualityComparer, IFormatProvider toStringFormatProvider) { this.set = set ?? throw new ArgumentNullException(nameof(set)); this.structuralEqualityComparer = structuralEqualityComparer ?? throw new ArgumentNullException(nameof(structuralEqualityComparer)); this.toStringFormatProvider = toStringFormatProvider ?? throw new ArgumentNullException(nameof(toStringFormatProvider)); }
public virtual int GetHashCode(IEqualityComparer comparer) => SetEqualityComparer <T> .GetHashCode(set, comparer);
public virtual bool Equals(object?other, IEqualityComparer comparer) => SetEqualityComparer <T> .Equals(set, other, comparer);
public void GetHashCode_throws_ane_for_null_collection(SetEqualityComparer <string> sut) { Assert.That(() => sut.GetHashCode(null), Throws.ArgumentNullException); }
public void GetHashCode_returns_same_value_for_the_same_collection_hashed_twice(SetEqualityComparer <string> sut) { var collection = new[] { "one", "two", "three" }; var result1 = sut.GetHashCode(collection); var result2 = sut.GetHashCode(collection); Assert.That(result1, Is.EqualTo(result2)); }
public void Equals_returns_false_for_two_collections_which_have_different_elements(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "two", "THREE" }; Assert.That(sut.Equals(collectionOne, collectionTwo), Is.False); }
public void Equals_returns_true_when_both_collecions_are_null(SetEqualityComparer <string> sut) { Assert.That(sut.Equals(null, null), Is.True); }
public void Equals_returns_false_when_first_collecion_is_null(SetEqualityComparer <string> sut) { var collectionTwo = new[] { "one", "two", "three" }; Assert.That(sut.Equals(null, collectionTwo), Is.False); }
public void GetHashCode_returns_same_value_for_two_collections_in_different_order(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "three", "two" }; var result1 = sut.GetHashCode(collectionOne); var result2 = sut.GetHashCode(collectionTwo); Assert.That(result1, Is.EqualTo(result2)); }
public int GetHashCode(IEqualityComparer comparer) { return(SetEqualityComparer <T> .GetHashCode(this, comparer)); }
public void GetHashCode_returns_different_value_for_two_collections_with_different_elements(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; var collectionTwo = new[] { "one", "two", "THREE" }; var result1 = sut.GetHashCode(collectionOne); var result2 = sut.GetHashCode(collectionTwo); Assert.That(result1, Is.Not.EqualTo(result2)); }
public void GetHashCode_returns_same_value_for_two_collections_with_same_elements_but_duplicates(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "two", "three", "two" }; var collectionTwo = new[] { "one", "three", "one", "two" }; var result1 = sut.GetHashCode(collectionOne); var result2 = sut.GetHashCode(collectionTwo); Assert.That(result1, Is.EqualTo(result2)); }
public bool Equals(object other, IEqualityComparer comparer) { return(SetEqualityComparer <T> .Equals(this, other, comparer)); }
public void Equals_returns_true_for_reference_equal_collections(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; Assert.That(sut.Equals(collectionOne, collectionOne), Is.True); }
protected ImmutableAdjacencyListGraph(IEqualityComparer <T> equalityComparer = null) { EqualityComparer = equalityComparer ?? new DefaultEqualityComparer(); SetEqualityComparerObj = new SetEqualityComparer <T>(EqualityComparer); EdgeSetEqualityComparer = new SetEqualityComparer <Edge <T> >(new EdgeEqualityComparer(EqualityComparer)); }
public void Equals_returns_false_when_second_collecion_is_null(SetEqualityComparer <string> sut) { var collectionOne = new[] { "one", "two", "three" }; Assert.That(sut.Equals(collectionOne, null), Is.False); }