コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void GetHashCode_ForSameObjects_ResultsAreEqual(string xString)
        {
            var uut = new SetEqualityComparer <string>();;

            var x = MakeTestSet(xString);

            uut.GetHashCode(x).ShouldBe(uut.GetHashCode(x));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        public void Equals_XIsSameAsY_ReturnsTrue(string xString)
        {
            var uut = new SetEqualityComparer <string>();;

            var x = MakeTestSet(xString);
            var y = x;

            uut.Equals(x, y).ShouldBeTrue();
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 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));
 }
コード例 #12
0
 public virtual int GetHashCode(IEqualityComparer comparer)
 => SetEqualityComparer <T> .GetHashCode(set, comparer);
コード例 #13
0
 public virtual bool Equals(object?other, IEqualityComparer comparer)
 => SetEqualityComparer <T> .Equals(set, other, comparer);
コード例 #14
0
 public void GetHashCode_throws_ane_for_null_collection(SetEqualityComparer <string> sut)
 {
     Assert.That(() => sut.GetHashCode(null), Throws.ArgumentNullException);
 }
コード例 #15
0
        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));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
 public void Equals_returns_true_when_both_collecions_are_null(SetEqualityComparer <string> sut)
 {
     Assert.That(sut.Equals(null, null), Is.True);
 }
コード例 #18
0
        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);
        }
コード例 #19
0
        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));
        }
コード例 #20
0
 public int GetHashCode(IEqualityComparer comparer)
 {
     return(SetEqualityComparer <T> .GetHashCode(this, comparer));
 }
コード例 #21
0
        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));
        }
コード例 #22
0
        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));
        }
コード例 #23
0
 public bool Equals(object other, IEqualityComparer comparer)
 {
     return(SetEqualityComparer <T> .Equals(this, other, comparer));
 }
コード例 #24
0
        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);
        }
コード例 #25
0
 protected ImmutableAdjacencyListGraph(IEqualityComparer <T> equalityComparer = null)
 {
     EqualityComparer        = equalityComparer ?? new DefaultEqualityComparer();
     SetEqualityComparerObj  = new SetEqualityComparer <T>(EqualityComparer);
     EdgeSetEqualityComparer = new SetEqualityComparer <Edge <T> >(new EdgeEqualityComparer(EqualityComparer));
 }
コード例 #26
0
        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);
        }