コード例 #1
0
        public void Equals_returns_true_for_two_collections_which_are_equal(ListEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True);
        }
コード例 #2
0
        public void Equals_returns_result_respecting_alternative_item_equality_comparer()
        {
            var sut = new ListEqualityComparer <string>(StringComparer.InvariantCultureIgnoreCase);

            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True);
        }
コード例 #3
0
        public void ListEqualityComparerReturnsTrueIfFirstAndSecondAreBothNull()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first  = null;
            IList <int> second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
コード例 #4
0
        public void ListEqualityComparerGetHashCodeReturnsZeroIfListIsNull()
        {
            const int expectedHashCode = 0;

            var comparer = new ListEqualityComparer <int>();

            IList <int> list = null;

            int result = comparer.GetHashCode(list);

            Assert.AreEqual(expectedHashCode, result);
        }
コード例 #5
0
        public void ListEqualityComparerGetHashCodeReturnsDefaultHashCodeIfListIsEmpty()
        {
            const int expectedHashCode = 23;

            var comparer = new ListEqualityComparer <int>();

            IList <int> list = new List <int>();

            int result = comparer.GetHashCode(list);

            Assert.AreEqual(expectedHashCode, result);
        }
コード例 #6
0
        public void GetHashCode_returns_same_value_for_collections_respecting_alternative_item_equality_comparer()
        {
            var sut = new ListEqualityComparer <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));
        }
コード例 #7
0
        public void ListEqualityComparerReturnsFalseIfSecondListIsNull()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IList <int> second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #8
0
        public void ListEqualityComparerReturnsTrueIfListsAreSameReference()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IList <int> second = first;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
コード例 #9
0
        public void ListEqualityComparerReturnsFalseIfFirstIsGreaterLengthThanSecond()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IList <int> second = new List <int>();

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #10
0
        public void GetHashCode_does_not_pass_null_items_to_equality_comparer_hash_code_method(IEqualityComparer <string> comparer)
        {
            var sut = new ListEqualityComparer <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
        public void ListEqualityComparerReturnsFalseIfFirstAndSecondListElementsAreNotTheSame()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IList <int> second = new List <int> {
                6, 7, 8, 9, 10
            };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #12
0
        public void ListEqualityComparerReturnsFalseIfFirstAndSecondListElementsAreTheSameButDifferentOrder()
        {
            var comparer = new ListEqualityComparer <int>();

            IList <int> first = new List <int> {
                1, 2, 3, 4, 5
            };
            IList <int> second = new List <int> {
                5, 4, 3, 2, 1
            };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #13
0
        public void ListEqualityComparerGetHashCodeReturnsSameHashCodeIfListContainsNullElements()
        {
            var comparer = new ListEqualityComparer <int?>();

            IList <int?> list = new List <int?> {
                1, 2, null, 4, 5
            };

            //get the HashCode 2000 times to confirm it is consistent for lifetime of the list
            HashSet <int> hashes = new HashSet <int>();

            for (int i = 0; i < 2000; i++)
            {
                hashes.Add(comparer.GetHashCode(list));
            }

            Assert.AreEqual(1, hashes.Count);
        }
コード例 #14
0
 public virtual bool Equals(object?other, IEqualityComparer comparer)
 => ListEqualityComparer <T> .Equals(Items, other, comparer);
コード例 #15
0
        public void GetHashCode_returns_same_value_for_the_same_collection_hashed_twice(ListEqualityComparer <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 ListEqualityComparerInitialisesWithSpecifiedElementComparer()
        {
            var comparer = new ListEqualityComparer <int>(EqualityComparer <int> .Default);

            Assert.IsNotNull(comparer);
        }
コード例 #17
0
        public void Equals_returns_false_when_first_collecion_is_null(ListEqualityComparer <string> sut)
        {
            var collectionTwo = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(null, collectionTwo), Is.False);
        }
コード例 #18
0
        public void Equals_returns_false_when_second_collecion_is_null(ListEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, null), Is.False);
        }
コード例 #19
0
        public void ListEqualityComparerInitialises()
        {
            var comparer = new ListEqualityComparer <int>();

            Assert.IsNotNull(comparer);
        }
コード例 #20
0
 public void Equals_returns_true_when_both_collecions_are_null(ListEqualityComparer <string> sut)
 {
     Assert.That(sut.Equals(null, null), Is.True);
 }
コード例 #21
0
        public void Equals_returns_true_for_reference_equal_collections(ListEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, collectionOne), Is.True);
        }
コード例 #22
0
        public void Equals_returns_false_for_two_collections_which_have_different_elements(ListEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.False);
        }
コード例 #23
0
 public int GetHashCode(IEqualityComparer comparer)
 {
     return(ListEqualityComparer <T> .GetHashCode(this, comparer));
 }
コード例 #24
0
ファイル: BasicOperations.cs プロジェクト: unity-alex/Fare
        /// <summary>
        /// Determinizes the given automaton using the given set of initial states.
        /// </summary>
        /// <param name="a">The automaton.</param>
        /// <param name="initialset">The initial states.</param>
        public static void Determinize(Automaton a, List<State> initialset)
        {
            char[] points = a.GetStartPoints();

            var comparer = new ListEqualityComparer<State>();

            // Subset construction.
            var sets = new Dictionary<List<State>, List<State>>(comparer);
            var worklist = new LinkedList<List<State>>();
            var newstate = new Dictionary<List<State>, State>(comparer);

            sets.Add(initialset, initialset);
            worklist.AddLast(initialset);
            a.Initial = new State();
            newstate.Add(initialset, a.Initial);

            while (worklist.Count > 0)
            {
                List<State> s = worklist.RemoveAndReturnFirst();
                State r;
                newstate.TryGetValue(s, out r);
                foreach (State q in s)
                {
                    if (q.Accept)
                    {
                        r.Accept = true;
                        break;
                    }
                }

                for (int n = 0; n < points.Length; n++)
                {
                    var set = new HashSet<State>();
                    foreach (State c in s)
                        foreach (Transition t in c.Transitions)
                            if (t.Min <= points[n] && points[n] <= t.Max)
                                set.Add(t.To);

                    var p = set.ToList();

                    if (!sets.ContainsKey(p))
                    {
                        sets.Add(p, p);
                        worklist.AddLast(p);
                        newstate.Add(p, new State());
                    }

                    State q;
                    newstate.TryGetValue(p, out q);
                    char min = points[n];
                    char max;
                    if (n + 1 < points.Length)
                    {
                        max = (char)(points[n + 1] - 1);
                    }
                    else
                    {
                        max = char.MaxValue;
                    }

                    r.Transitions.Add(new Transition(min, max, q));
                }
            }

            a.IsDeterministic = true;
            a.RemoveDeadTransitions();
        }
コード例 #25
0
        public void GetHashCode_returns_different_value_for_two_collections_with_different_elements(ListEqualityComparer <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));
        }
コード例 #26
0
 public virtual int GetHashCode(IEqualityComparer comparer)
 => ListEqualityComparer <T> .GetHashCode(this, comparer);
コード例 #27
0
        public void Equals_returns_false_for_two_collections_which_are_equal_but_have_duplicates(ListEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "two", "three", "two" };
            var collectionTwo = new[] { "one", "three", "one", "two" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.False);
        }
コード例 #28
0
        public void Equals_returns_true_comparing_equivalent_object_collections_which_are_equatable_but_not_comparable(ListEqualityComparer <Pet> sut)
        {
            var coll1 = new[] { new Pet {
                                    Name = "A"
                                }, new Pet {
                                    Name = "B"
                                }, new Pet {
                                    Name = "C"
                                }, };
            var coll2 = new[] { new Pet {
                                    Name = "A"
                                }, new Pet {
                                    Name = "B"
                                }, new Pet {
                                    Name = "C"
                                }, };

            Assert.That(sut.Equals(coll1, coll2), Is.True);
        }
コード例 #29
0
 internal ReadOnlyList(IList <T> list, ListEqualityComparer <T> structuralEqualityComparer, IFormatProvider toStringFormatProvider)
     : base(list)
 {
     this.structuralEqualityComparer = structuralEqualityComparer ?? throw new ArgumentNullException(nameof(structuralEqualityComparer));
     this.toStringFormatProvider     = toStringFormatProvider ?? throw new ArgumentNullException(nameof(toStringFormatProvider));
 }
コード例 #30
0
ファイル: MD5Checksum.cs プロジェクト: SmaSTra/SmaSTra
        public override bool Equals(object obj)
        {
            MD5Checksum other = obj as MD5Checksum;

            return(other != null && ListEqualityComparer <byte> .Equals(this.Bytes, other.Bytes));
        }
コード例 #31
0
 public bool Equals(object other, IEqualityComparer comparer)
 {
     return(ListEqualityComparer <T> .Equals(this, other, comparer));
 }