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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public virtual bool Equals(object?other, IEqualityComparer comparer) => ListEqualityComparer <T> .Equals(Items, other, comparer);
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)); }
public void ListEqualityComparerInitialisesWithSpecifiedElementComparer() { var comparer = new ListEqualityComparer <int>(EqualityComparer <int> .Default); Assert.IsNotNull(comparer); }
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); }
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); }
public void ListEqualityComparerInitialises() { var comparer = new ListEqualityComparer <int>(); Assert.IsNotNull(comparer); }
public void Equals_returns_true_when_both_collecions_are_null(ListEqualityComparer <string> sut) { Assert.That(sut.Equals(null, null), Is.True); }
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); }
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); }
public int GetHashCode(IEqualityComparer comparer) { return(ListEqualityComparer <T> .GetHashCode(this, comparer)); }
/// <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(); }
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)); }
public virtual int GetHashCode(IEqualityComparer comparer) => ListEqualityComparer <T> .GetHashCode(this, comparer);
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); }
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); }
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)); }
public override bool Equals(object obj) { MD5Checksum other = obj as MD5Checksum; return(other != null && ListEqualityComparer <byte> .Equals(this.Bytes, other.Bytes)); }
public bool Equals(object other, IEqualityComparer comparer) { return(ListEqualityComparer <T> .Equals(this, other, comparer)); }