public virtual void LinkedHashSetTest() { LinkedHashSet <int> set1 = new LinkedHashSet <int>(); set1.Add(5); set1.Add(2); set1.Add(3); set1.Add(5); Assert.AreEqual(5, set1.First()); Assert.AreEqual(3, set1.Last()); Assert.AreEqual(3, set1.Count); LinkedHashSet <int> set2 = new LinkedHashSet <int>(); set2.Add(2); set2.Add(5); Assert.True(set1.IsSupersetOf(set2)); Assert.True(set1.IsProperSupersetOf(set2)); Assert.True(set2.IsSubsetOf(set1)); Assert.True(set2.IsProperSubsetOf(set1)); Assert.False(set2.IsSupersetOf(set1)); LinkedHashSet <int> set3 = new LinkedHashSet <int>(); set3.Add(5); set3.Add(2); Assert.True(set3.SetEquals(set2)); }
public void LinkedHashSet_Generic_Constructor_IEnumerable_WithManyDuplicates(int count) { SCG.IEnumerable <T> items = CreateEnumerable(EnumerableType.List, null, count, 0, 0); LinkedHashSet <T> hashSetFromDuplicates = new LinkedHashSet <T>(Enumerable.Range(0, 40).SelectMany(i => items).ToArray()); LinkedHashSet <T> hashSetFromNoDuplicates = new LinkedHashSet <T>(items); Assert.True(hashSetFromNoDuplicates.SetEquals(hashSetFromDuplicates)); }
public void LinkedHashSet_Generic_Constructor_IEnumerable(EnumerableType enumerableType, int setLength, int enumerableLength, int numberOfMatchingElements, int numberOfDuplicateElements) { _ = setLength; _ = numberOfMatchingElements; SCG.IEnumerable <T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements); LinkedHashSet <T> set = new LinkedHashSet <T>(enumerable); Assert.True(set.SetEquals(enumerable)); }
public void LinkedHashSet_Generic_TrimExcess_Repeatedly(int setLength) { LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength); List <T> expected = set.ToList(); set.TrimExcess(); set.TrimExcess(); set.TrimExcess(); Assert.True(set.SetEquals(expected)); }
public void LinkedHashSet_Generic_Constructor_LinkedHashSet_SparselyFilled(int count) { LinkedHashSet <T> source = (LinkedHashSet <T>)CreateEnumerable(EnumerableType.LinkedHashSet, null, count, 0, 0); List <T> sourceElements = source.ToList(); foreach (int i in NonSquares(count)) { source.Remove(sourceElements[i]);// Unevenly spaced survivors increases chance of catching any spacing-related bugs. } LinkedHashSet <T> set = new LinkedHashSet <T>(source, GetIEqualityComparer()); Assert.True(set.SetEquals(source)); }
public void SetComparer_SetEqualsTests() { SCG.List <T> objects = new SCG.List <T>() { CreateT(1), CreateT(2), CreateT(3), CreateT(4), CreateT(5), CreateT(6) }; var set = new LinkedHashSet <LinkedHashSet <T> >() { new LinkedHashSet <T> { objects[0], objects[1], objects[2] }, new LinkedHashSet <T> { objects[3], objects[4], objects[5] } }; var noComparerSet = new LinkedHashSet <LinkedHashSet <T> >() { new LinkedHashSet <T> { objects[0], objects[1], objects[2] }, new LinkedHashSet <T> { objects[3], objects[4], objects[5] } }; var comparerSet1 = new LinkedHashSet <LinkedHashSet <T> >(SetEqualityComparer <T> .Default) { new LinkedHashSet <T> { objects[0], objects[1], objects[2] }, new LinkedHashSet <T> { objects[3], objects[4], objects[5] } }; var comparerSet2 = new LinkedHashSet <LinkedHashSet <T> >(SetEqualityComparer <T> .Default) { new LinkedHashSet <T> { objects[3], objects[4], objects[5] }, new LinkedHashSet <T> { objects[0], objects[1], objects[2] } }; Assert.True(noComparerSet.SetEquals(set)); // Our implementation is structurally equatable by default Assert.True(comparerSet1.SetEquals(set)); Assert.True(comparerSet2.SetEquals(set)); }
public void LinkedHashSet_Generic_TrimExcess_AfterRemovingOneElement(int setLength) { if (setLength > 0) { LinkedHashSet <T> set = (LinkedHashSet <T>)GenericISetFactory(setLength); List <T> expected = set.ToList(); T elementToRemove = set.ElementAt(0); set.TrimExcess(); Assert.True(set.Remove(elementToRemove)); expected.Remove(elementToRemove); set.TrimExcess(); Assert.True(set.SetEquals(expected)); } }
private List <LALRState> CreateLALRState(CachedGrammar cg) { List <LALRState> clr = CreateCLRState(cg); List <LALRState> lalr = new List <LALRState>(); int cnt = clr.Count; for (int x = 0; x < cnt; x++) { LALRState current_state = clr[x]; for (int z = x + 1; z < cnt;) { LinkedHashSet <LRxItem> xlist = current_state.items; LinkedHashSet <LRxItem> zlist = clr[z].items; IEqualityComparer <LRxItem> save = xlist.Comparer; xlist.Comparer = LRxItemComparerSlim.Instance; zlist.Comparer = LRxItemComparerSlim.Instance; if (xlist.SetEquals(zlist)) { IEnumerator <LRxItem> e1 = xlist.GetEnumerator(); while (e1.MoveNext()) { LRxItem now = e1.Current; IEnumerator <LRxItem> e2 = zlist.GetEnumerator(); while (e2.MoveNext()) { if (now.CoreEquals(e2.Current)) { now.lookahead.UnionWith(e2.Current.lookahead); break; } } e2.Dispose(); } e1.Dispose(); xlist.Comparer = save; zlist.Comparer = save; for (int a = 0; a < cnt; a++) { Map <LALRState> map = clr[a].map; KeyValuePair <int, LALRState>[] kvs = map.ToArray(); for (int b = 0, bm = kvs.Length; b < bm; b++) { if (kvs[b].Value.items.SetEquals(zlist)) { map.Add(kvs[b].Key, current_state); } } } clr.RemoveAt(z); cnt--; } else { xlist.Comparer = save; zlist.Comparer = save; z++; } } lalr.Add(current_state); } clr.Clear(); return(lalr); }
public static void LinkedHashSetTest() { int[] setEmpty = { }; int[] set1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int[] set2 = { 1, 2, 3, 4, 5, 6, 6, 8, 9 }; int[] set3 = { 1, 2, 3, 4, 5, 6, 8, 9, 0 }; LinkedHashSet <int> lhsEmpty = new LinkedHashSet <int>(); LinkedHashSet <int> lhs1 = new LinkedHashSet <int>(set1); LinkedHashSet <int> lhs2 = new LinkedHashSet <int>(set2); LinkedHashSet <int> lhs3 = new LinkedHashSet <int>(set3); HashSet <int> hsEmpty = new HashSet <int>(); HashSet <int> hs1 = new HashSet <int>(set1); HashSet <int> hs2 = new HashSet <int>(set2); HashSet <int> hs3 = new HashSet <int>(set3); #region Pseudo-LINQ-Extensions Assert.AreEqual(1, lhs1.First()); Assert.AreEqual(9, lhs1.Last()); Assert.AreEqual(0, lhs3.Last()); Assert.Throws <InvalidOperationException>(() => lhsEmpty.First()); Assert.Throws <InvalidOperationException>(() => lhsEmpty.Last()); Assert.DoesNotThrow(() => lhsEmpty.FirstOrDefault()); Assert.DoesNotThrow(() => lhsEmpty.LastOrDefault()); Assert.AreEqual(default(int), lhsEmpty.FirstOrDefault()); Assert.AreEqual(default(int), lhsEmpty.LastOrDefault()); Assert.DoesNotThrow(() => lhsEmpty.Reverse()); List <int> reversed = new List <int>(lhs3.Reverse()); Assert.AreEqual(lhs3.Count, reversed.Count); Assert.AreEqual(0, reversed[0]); Assert.AreEqual(9, reversed[1]); Assert.AreEqual(8, reversed[2]); Assert.AreEqual(6, reversed[3]); Assert.AreEqual(5, reversed[4]); Assert.AreEqual(4, reversed[5]); Assert.AreEqual(3, reversed[6]); Assert.AreEqual(2, reversed[7]); Assert.AreEqual(1, reversed[8]); #endregion #region SetEquals Assert.IsTrue(lhsEmpty.SetEquals(lhsEmpty)); Assert.IsTrue(lhs1.SetEquals(lhs1)); Assert.IsTrue(lhs2.SetEquals(lhs2)); Assert.IsTrue(lhs3.SetEquals(lhs3)); Assert.IsTrue(lhsEmpty.SetEquals(hsEmpty)); Assert.IsTrue(lhs1.SetEquals(hs1)); Assert.IsTrue(lhs2.SetEquals(hs2)); Assert.IsTrue(lhs3.SetEquals(hs3)); Assert.IsTrue(lhsEmpty.SetEquals(setEmpty)); Assert.IsTrue(lhs1.SetEquals(set1)); Assert.IsTrue(lhs2.SetEquals(set2)); Assert.IsTrue(lhs3.SetEquals(set3)); Assert.IsTrue(lhsEmpty.SetEquals(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.SetEquals(GetEnumerator(set1))); Assert.IsTrue(lhs2.SetEquals(GetEnumerator(set2))); Assert.IsTrue(lhs3.SetEquals(GetEnumerator(set3))); Assert.IsFalse(lhsEmpty.SetEquals(lhs1)); Assert.IsFalse(lhsEmpty.SetEquals(lhs2)); Assert.IsFalse(lhsEmpty.SetEquals(lhs3)); Assert.IsFalse(lhsEmpty.SetEquals(hs1)); Assert.IsFalse(lhsEmpty.SetEquals(hs2)); Assert.IsFalse(lhsEmpty.SetEquals(hs3)); Assert.IsFalse(lhsEmpty.SetEquals(set1)); Assert.IsFalse(lhsEmpty.SetEquals(set2)); Assert.IsFalse(lhsEmpty.SetEquals(set3)); Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set1))); Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set2))); Assert.IsFalse(lhsEmpty.SetEquals(GetEnumerator(set3))); Assert.IsFalse(lhs1.SetEquals(lhsEmpty)); Assert.IsFalse(lhs1.SetEquals(lhs2)); Assert.IsFalse(lhs1.SetEquals(lhs3)); Assert.IsFalse(lhs1.SetEquals(hsEmpty)); Assert.IsFalse(lhs1.SetEquals(hs2)); Assert.IsFalse(lhs1.SetEquals(hs3)); Assert.IsFalse(lhs1.SetEquals(setEmpty)); Assert.IsFalse(lhs1.SetEquals(set2)); Assert.IsFalse(lhs1.SetEquals(set3)); Assert.IsFalse(lhs1.SetEquals(GetEnumerator(setEmpty))); Assert.IsFalse(lhs1.SetEquals(GetEnumerator(set2))); Assert.IsFalse(lhs1.SetEquals(GetEnumerator(set3))); Assert.IsFalse(lhs2.SetEquals(lhsEmpty)); Assert.IsFalse(lhs2.SetEquals(lhs1)); Assert.IsFalse(lhs2.SetEquals(lhs3)); Assert.IsFalse(lhs2.SetEquals(hsEmpty)); Assert.IsFalse(lhs2.SetEquals(hs1)); Assert.IsFalse(lhs2.SetEquals(hs3)); Assert.IsFalse(lhs2.SetEquals(setEmpty)); Assert.IsFalse(lhs2.SetEquals(set1)); Assert.IsFalse(lhs2.SetEquals(set3)); Assert.IsFalse(lhs2.SetEquals(GetEnumerator(setEmpty))); Assert.IsFalse(lhs2.SetEquals(GetEnumerator(set1))); Assert.IsFalse(lhs2.SetEquals(GetEnumerator(set3))); Assert.IsFalse(lhs3.SetEquals(lhsEmpty)); Assert.IsFalse(lhs3.SetEquals(lhs1)); Assert.IsFalse(lhs3.SetEquals(lhs2)); Assert.IsFalse(lhs3.SetEquals(hsEmpty)); Assert.IsFalse(lhs3.SetEquals(hs1)); Assert.IsFalse(lhs3.SetEquals(hs2)); Assert.IsFalse(lhs3.SetEquals(setEmpty)); Assert.IsFalse(lhs3.SetEquals(set1)); Assert.IsFalse(lhs3.SetEquals(set2)); Assert.IsFalse(lhs3.SetEquals(GetEnumerator(setEmpty))); Assert.IsFalse(lhs3.SetEquals(GetEnumerator(set1))); Assert.IsFalse(lhs3.SetEquals(GetEnumerator(set2))); #endregion #region Overlaps Assert.IsFalse(lhsEmpty.Overlaps(lhsEmpty)); Assert.IsTrue(lhs1.Overlaps(lhs1)); Assert.IsTrue(lhs2.Overlaps(lhs2)); Assert.IsTrue(lhs3.Overlaps(lhs3)); Assert.IsFalse(lhsEmpty.Overlaps(hsEmpty)); Assert.IsTrue(lhs1.Overlaps(hs1)); Assert.IsTrue(lhs2.Overlaps(hs2)); Assert.IsTrue(lhs3.Overlaps(hs3)); Assert.IsFalse(lhsEmpty.Overlaps(setEmpty)); Assert.IsTrue(lhs1.Overlaps(set1)); Assert.IsTrue(lhs2.Overlaps(set2)); Assert.IsTrue(lhs3.Overlaps(set3)); Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set1))); Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set2))); Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set3))); Assert.IsFalse(lhsEmpty.Overlaps(lhs1)); Assert.IsFalse(lhsEmpty.Overlaps(lhs2)); Assert.IsFalse(lhsEmpty.Overlaps(lhs3)); Assert.IsFalse(lhsEmpty.Overlaps(hs1)); Assert.IsFalse(lhsEmpty.Overlaps(hs2)); Assert.IsFalse(lhsEmpty.Overlaps(hs3)); Assert.IsFalse(lhsEmpty.Overlaps(set1)); Assert.IsFalse(lhsEmpty.Overlaps(set2)); Assert.IsFalse(lhsEmpty.Overlaps(set3)); Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set1))); Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set2))); Assert.IsFalse(lhsEmpty.Overlaps(GetEnumerator(set3))); Assert.IsFalse(lhs1.Overlaps(lhsEmpty)); Assert.IsTrue(lhs1.Overlaps(lhs2)); Assert.IsTrue(lhs1.Overlaps(lhs3)); Assert.IsFalse(lhs1.Overlaps(hsEmpty)); Assert.IsTrue(lhs1.Overlaps(hs2)); Assert.IsTrue(lhs1.Overlaps(hs3)); Assert.IsFalse(lhs1.Overlaps(setEmpty)); Assert.IsTrue(lhs1.Overlaps(set2)); Assert.IsTrue(lhs1.Overlaps(set3)); Assert.IsFalse(lhs1.Overlaps(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set2))); Assert.IsTrue(lhs1.Overlaps(GetEnumerator(set3))); Assert.IsFalse(lhs2.Overlaps(lhsEmpty)); Assert.IsTrue(lhs2.Overlaps(lhs1)); Assert.IsTrue(lhs2.Overlaps(lhs3)); Assert.IsFalse(lhs2.Overlaps(hsEmpty)); Assert.IsTrue(lhs2.Overlaps(hs1)); Assert.IsTrue(lhs2.Overlaps(hs3)); Assert.IsFalse(lhs2.Overlaps(setEmpty)); Assert.IsTrue(lhs2.Overlaps(set1)); Assert.IsTrue(lhs2.Overlaps(set3)); Assert.IsFalse(lhs2.Overlaps(GetEnumerator(setEmpty))); Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set1))); Assert.IsTrue(lhs2.Overlaps(GetEnumerator(set3))); Assert.IsFalse(lhs3.Overlaps(lhsEmpty)); Assert.IsTrue(lhs3.Overlaps(lhs1)); Assert.IsTrue(lhs3.Overlaps(lhs2)); Assert.IsFalse(lhs3.Overlaps(hsEmpty)); Assert.IsTrue(lhs3.Overlaps(hs1)); Assert.IsTrue(lhs3.Overlaps(hs2)); Assert.IsFalse(lhs3.Overlaps(setEmpty)); Assert.IsTrue(lhs3.Overlaps(set1)); Assert.IsTrue(lhs3.Overlaps(set2)); Assert.IsFalse(lhs3.Overlaps(GetEnumerator(setEmpty))); Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set1))); Assert.IsTrue(lhs3.Overlaps(GetEnumerator(set2))); #endregion #region IsSubsetOf Assert.IsTrue(lhsEmpty.IsSubsetOf(lhsEmpty)); Assert.IsTrue(lhs1.IsSubsetOf(lhs1)); Assert.IsTrue(lhs2.IsSubsetOf(lhs2)); Assert.IsTrue(lhs3.IsSubsetOf(lhs3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(hsEmpty)); Assert.IsTrue(lhs1.IsSubsetOf(hs1)); Assert.IsTrue(lhs2.IsSubsetOf(hs2)); Assert.IsTrue(lhs3.IsSubsetOf(hs3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(setEmpty)); Assert.IsTrue(lhs1.IsSubsetOf(set1)); Assert.IsTrue(lhs2.IsSubsetOf(set2)); Assert.IsTrue(lhs3.IsSubsetOf(set3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.IsSubsetOf(GetEnumerator(set1))); Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set2))); Assert.IsTrue(lhs3.IsSubsetOf(GetEnumerator(set3))); Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs1)); Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs2)); Assert.IsTrue(lhsEmpty.IsSubsetOf(lhs3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(hs1)); Assert.IsTrue(lhsEmpty.IsSubsetOf(hs2)); Assert.IsTrue(lhsEmpty.IsSubsetOf(hs3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(set1)); Assert.IsTrue(lhsEmpty.IsSubsetOf(set2)); Assert.IsTrue(lhsEmpty.IsSubsetOf(set3)); Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set1))); Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set2))); Assert.IsTrue(lhsEmpty.IsSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs1.IsSubsetOf(lhsEmpty)); Assert.IsFalse(lhs1.IsSubsetOf(lhs2)); Assert.IsFalse(lhs1.IsSubsetOf(lhs3)); Assert.IsFalse(lhs1.IsSubsetOf(hsEmpty)); Assert.IsFalse(lhs1.IsSubsetOf(hs2)); Assert.IsFalse(lhs1.IsSubsetOf(hs3)); Assert.IsFalse(lhs1.IsSubsetOf(setEmpty)); Assert.IsFalse(lhs1.IsSubsetOf(set2)); Assert.IsFalse(lhs1.IsSubsetOf(set3)); Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(set2))); Assert.IsFalse(lhs1.IsSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs2.IsSubsetOf(lhsEmpty)); Assert.IsTrue(lhs2.IsSubsetOf(lhs1)); Assert.IsTrue(lhs2.IsSubsetOf(lhs3)); Assert.IsFalse(lhs2.IsSubsetOf(hsEmpty)); Assert.IsTrue(lhs2.IsSubsetOf(hs1)); Assert.IsTrue(lhs2.IsSubsetOf(hs3)); Assert.IsFalse(lhs2.IsSubsetOf(setEmpty)); Assert.IsTrue(lhs2.IsSubsetOf(set1)); Assert.IsTrue(lhs2.IsSubsetOf(set3)); Assert.IsFalse(lhs2.IsSubsetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set1))); Assert.IsTrue(lhs2.IsSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs3.IsSubsetOf(lhsEmpty)); Assert.IsFalse(lhs3.IsSubsetOf(lhs1)); Assert.IsFalse(lhs3.IsSubsetOf(lhs2)); Assert.IsFalse(lhs3.IsSubsetOf(hsEmpty)); Assert.IsFalse(lhs3.IsSubsetOf(hs1)); Assert.IsFalse(lhs3.IsSubsetOf(hs2)); Assert.IsFalse(lhs3.IsSubsetOf(setEmpty)); Assert.IsFalse(lhs3.IsSubsetOf(set1)); Assert.IsFalse(lhs3.IsSubsetOf(set2)); Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(set1))); Assert.IsFalse(lhs3.IsSubsetOf(GetEnumerator(set2))); #endregion #region IsProperSubsetOf Assert.IsFalse(lhsEmpty.IsProperSubsetOf(lhsEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(lhs1)); Assert.IsFalse(lhs2.IsProperSubsetOf(lhs2)); Assert.IsFalse(lhs3.IsProperSubsetOf(lhs3)); Assert.IsFalse(lhsEmpty.IsProperSubsetOf(hsEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(hs1)); Assert.IsFalse(lhs2.IsProperSubsetOf(hs2)); Assert.IsFalse(lhs3.IsProperSubsetOf(hs3)); Assert.IsFalse(lhsEmpty.IsProperSubsetOf(setEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(set1)); Assert.IsFalse(lhs2.IsProperSubsetOf(set2)); Assert.IsFalse(lhs3.IsProperSubsetOf(set3)); Assert.IsFalse(lhsEmpty.IsProperSubsetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set1))); Assert.IsFalse(lhs2.IsProperSubsetOf(GetEnumerator(set2))); Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set3))); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs1)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs2)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(lhs3)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs1)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs2)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(hs3)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set1)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set2)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(set3)); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set1))); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set2))); Assert.IsTrue(lhsEmpty.IsProperSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs1.IsProperSubsetOf(lhsEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(lhs2)); Assert.IsFalse(lhs1.IsProperSubsetOf(lhs3)); Assert.IsFalse(lhs1.IsProperSubsetOf(hsEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(hs2)); Assert.IsFalse(lhs1.IsProperSubsetOf(hs3)); Assert.IsFalse(lhs1.IsProperSubsetOf(setEmpty)); Assert.IsFalse(lhs1.IsProperSubsetOf(set2)); Assert.IsFalse(lhs1.IsProperSubsetOf(set3)); Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set2))); Assert.IsFalse(lhs1.IsProperSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs2.IsProperSubsetOf(lhsEmpty)); Assert.IsTrue(lhs2.IsProperSubsetOf(lhs1)); Assert.IsTrue(lhs2.IsProperSubsetOf(lhs3)); Assert.IsFalse(lhs2.IsProperSubsetOf(hsEmpty)); Assert.IsTrue(lhs2.IsProperSubsetOf(hs1)); Assert.IsTrue(lhs2.IsProperSubsetOf(hs3)); Assert.IsFalse(lhs2.IsProperSubsetOf(setEmpty)); Assert.IsTrue(lhs2.IsProperSubsetOf(set1)); Assert.IsTrue(lhs2.IsProperSubsetOf(set3)); Assert.IsFalse(lhs2.IsProperSubsetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs2.IsProperSubsetOf(GetEnumerator(set1))); Assert.IsTrue(lhs2.IsProperSubsetOf(GetEnumerator(set3))); Assert.IsFalse(lhs3.IsProperSubsetOf(lhsEmpty)); Assert.IsFalse(lhs3.IsProperSubsetOf(lhs1)); Assert.IsFalse(lhs3.IsProperSubsetOf(lhs2)); Assert.IsFalse(lhs3.IsProperSubsetOf(hsEmpty)); Assert.IsFalse(lhs3.IsProperSubsetOf(hs1)); Assert.IsFalse(lhs3.IsProperSubsetOf(hs2)); Assert.IsFalse(lhs3.IsProperSubsetOf(setEmpty)); Assert.IsFalse(lhs3.IsProperSubsetOf(set1)); Assert.IsFalse(lhs3.IsProperSubsetOf(set2)); Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set1))); Assert.IsFalse(lhs3.IsProperSubsetOf(GetEnumerator(set2))); #endregion #region IsSupersetOf Assert.IsTrue(lhsEmpty.IsSupersetOf(lhsEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(lhs1)); Assert.IsTrue(lhs2.IsSupersetOf(lhs2)); Assert.IsTrue(lhs3.IsSupersetOf(lhs3)); Assert.IsTrue(lhsEmpty.IsSupersetOf(hsEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(hs1)); Assert.IsTrue(lhs2.IsSupersetOf(hs2)); Assert.IsTrue(lhs3.IsSupersetOf(hs3)); Assert.IsTrue(lhsEmpty.IsSupersetOf(setEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(set1)); Assert.IsTrue(lhs2.IsSupersetOf(set2)); Assert.IsTrue(lhs3.IsSupersetOf(set3)); Assert.IsTrue(lhsEmpty.IsSupersetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(set1))); Assert.IsTrue(lhs2.IsSupersetOf(GetEnumerator(set2))); Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(set3))); Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs1)); Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs2)); Assert.IsFalse(lhsEmpty.IsSupersetOf(lhs3)); Assert.IsFalse(lhsEmpty.IsSupersetOf(hs1)); Assert.IsFalse(lhsEmpty.IsSupersetOf(hs2)); Assert.IsFalse(lhsEmpty.IsSupersetOf(hs3)); Assert.IsFalse(lhsEmpty.IsSupersetOf(set1)); Assert.IsFalse(lhsEmpty.IsSupersetOf(set2)); Assert.IsFalse(lhsEmpty.IsSupersetOf(set3)); Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set1))); Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set2))); Assert.IsFalse(lhsEmpty.IsSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs1.IsSupersetOf(lhsEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(lhs2)); Assert.IsFalse(lhs1.IsSupersetOf(lhs3)); Assert.IsTrue(lhs1.IsSupersetOf(hsEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(hs2)); Assert.IsFalse(lhs1.IsSupersetOf(hs3)); Assert.IsTrue(lhs1.IsSupersetOf(setEmpty)); Assert.IsTrue(lhs1.IsSupersetOf(set2)); Assert.IsFalse(lhs1.IsSupersetOf(set3)); Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.IsSupersetOf(GetEnumerator(set2))); Assert.IsFalse(lhs1.IsSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs2.IsSupersetOf(lhsEmpty)); Assert.IsFalse(lhs2.IsSupersetOf(lhs1)); Assert.IsFalse(lhs2.IsSupersetOf(lhs3)); Assert.IsTrue(lhs2.IsSupersetOf(hsEmpty)); Assert.IsFalse(lhs2.IsSupersetOf(hs1)); Assert.IsFalse(lhs2.IsSupersetOf(hs3)); Assert.IsTrue(lhs2.IsSupersetOf(setEmpty)); Assert.IsFalse(lhs2.IsSupersetOf(set1)); Assert.IsFalse(lhs2.IsSupersetOf(set3)); Assert.IsTrue(lhs2.IsSupersetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs2.IsSupersetOf(GetEnumerator(set1))); Assert.IsFalse(lhs2.IsSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs3.IsSupersetOf(lhsEmpty)); Assert.IsFalse(lhs3.IsSupersetOf(lhs1)); Assert.IsTrue(lhs3.IsSupersetOf(lhs2)); Assert.IsTrue(lhs3.IsSupersetOf(hsEmpty)); Assert.IsFalse(lhs3.IsSupersetOf(hs1)); Assert.IsTrue(lhs3.IsSupersetOf(hs2)); Assert.IsTrue(lhs3.IsSupersetOf(setEmpty)); Assert.IsFalse(lhs3.IsSupersetOf(set1)); Assert.IsTrue(lhs3.IsSupersetOf(set2)); Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs3.IsSupersetOf(GetEnumerator(set1))); Assert.IsTrue(lhs3.IsSupersetOf(GetEnumerator(set2))); #endregion #region IsProperSupersetOf Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhsEmpty)); Assert.IsFalse(lhs1.IsProperSupersetOf(lhs1)); Assert.IsFalse(lhs2.IsProperSupersetOf(lhs2)); Assert.IsFalse(lhs3.IsProperSupersetOf(lhs3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hsEmpty)); Assert.IsFalse(lhs1.IsProperSupersetOf(hs1)); Assert.IsFalse(lhs2.IsProperSupersetOf(hs2)); Assert.IsFalse(lhs3.IsProperSupersetOf(hs3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(setEmpty)); Assert.IsFalse(lhs1.IsProperSupersetOf(set1)); Assert.IsFalse(lhs2.IsProperSupersetOf(set2)); Assert.IsFalse(lhs3.IsProperSupersetOf(set3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs1.IsProperSupersetOf(GetEnumerator(set1))); Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set2))); Assert.IsFalse(lhs3.IsProperSupersetOf(GetEnumerator(set3))); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs1)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs2)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(lhs3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs1)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs2)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(hs3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set1)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set2)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(set3)); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set1))); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set2))); Assert.IsFalse(lhsEmpty.IsProperSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs1.IsProperSupersetOf(lhsEmpty)); Assert.IsTrue(lhs1.IsProperSupersetOf(lhs2)); Assert.IsFalse(lhs1.IsProperSupersetOf(lhs3)); Assert.IsTrue(lhs1.IsProperSupersetOf(hsEmpty)); Assert.IsTrue(lhs1.IsProperSupersetOf(hs2)); Assert.IsFalse(lhs1.IsProperSupersetOf(hs3)); Assert.IsTrue(lhs1.IsProperSupersetOf(setEmpty)); Assert.IsTrue(lhs1.IsProperSupersetOf(set2)); Assert.IsFalse(lhs1.IsProperSupersetOf(set3)); Assert.IsTrue(lhs1.IsProperSupersetOf(GetEnumerator(setEmpty))); Assert.IsTrue(lhs1.IsProperSupersetOf(GetEnumerator(set2))); Assert.IsFalse(lhs1.IsProperSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs2.IsProperSupersetOf(lhsEmpty)); Assert.IsFalse(lhs2.IsProperSupersetOf(lhs1)); Assert.IsFalse(lhs2.IsProperSupersetOf(lhs3)); Assert.IsTrue(lhs2.IsProperSupersetOf(hsEmpty)); Assert.IsFalse(lhs2.IsProperSupersetOf(hs1)); Assert.IsFalse(lhs2.IsProperSupersetOf(hs3)); Assert.IsTrue(lhs2.IsProperSupersetOf(setEmpty)); Assert.IsFalse(lhs2.IsProperSupersetOf(set1)); Assert.IsFalse(lhs2.IsProperSupersetOf(set3)); Assert.IsTrue(lhs2.IsProperSupersetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set1))); Assert.IsFalse(lhs2.IsProperSupersetOf(GetEnumerator(set3))); Assert.IsTrue(lhs3.IsProperSupersetOf(lhsEmpty)); Assert.IsFalse(lhs3.IsProperSupersetOf(lhs1)); Assert.IsTrue(lhs3.IsProperSupersetOf(lhs2)); Assert.IsTrue(lhs3.IsProperSupersetOf(hsEmpty)); Assert.IsFalse(lhs3.IsProperSupersetOf(hs1)); Assert.IsTrue(lhs3.IsProperSupersetOf(hs2)); Assert.IsTrue(lhs3.IsProperSupersetOf(setEmpty)); Assert.IsFalse(lhs3.IsProperSupersetOf(set1)); Assert.IsTrue(lhs3.IsProperSupersetOf(set2)); Assert.IsTrue(lhs3.IsProperSupersetOf(GetEnumerator(setEmpty))); Assert.IsFalse(lhs3.IsProperSupersetOf(GetEnumerator(set1))); Assert.IsTrue(lhs3.IsProperSupersetOf(GetEnumerator(set2))); #endregion #region Remove, Add and Contains Assert.IsTrue(lhs1.Remove(7)); Assert.AreEqual(lhs1.Count, 8); Assert.IsTrue(lhs1.SetEquals(lhs2)); Assert.IsFalse(lhs1.Remove(7)); Assert.AreEqual(lhs1.Count, 8); Assert.IsTrue(lhs1.Add(0)); Assert.AreEqual(lhs1.Count, 9); Assert.IsTrue(lhs1.SetEquals(lhs3)); Assert.IsFalse(lhs1.Add(0)); Assert.AreEqual(lhs1.Count, 9); Assert.IsTrue(lhs1.Contains(3)); Assert.IsTrue(lhs1.Contains(0)); Assert.IsFalse(lhs1.Contains(7)); Assert.IsFalse(lhs3.Contains(7)); lhs1.Clear(); Assert.AreEqual(lhs1.Count, 0); Assert.IsTrue(lhs1.SetEquals(lhsEmpty)); #endregion #region ExceptWith lhs1 = new LinkedHashSet <int>(set1); lhs2 = new LinkedHashSet <int>(set2); lhs3 = new LinkedHashSet <int>(set3); lhs1.ExceptWith(lhs2); Assert.AreEqual(lhs1.Count, 1); Assert.IsTrue(lhs1.Contains(7)); lhs2.ExceptWith(lhs1); Assert.IsTrue(lhs2.SetEquals(set2)); lhs1.ExceptWith(lhs3); Assert.AreEqual(lhs1.Count, 1); Assert.IsTrue(lhs1.Contains(7)); lhs3.ExceptWith(lhs2); Assert.AreEqual(lhs3.Count, 1); Assert.IsTrue(lhs3.Contains(0)); #endregion #region UnionWith lhs1 = new LinkedHashSet <int>(set1); lhs2 = new LinkedHashSet <int>(set2); lhs3 = new LinkedHashSet <int>(set3); lhs1.UnionWith(lhs2); Assert.IsTrue(lhs1.SetEquals(set1)); lhs3.UnionWith(lhs2); Assert.IsTrue(lhs3.SetEquals(set3)); lhs3.UnionWith(lhs1); Assert.IsTrue(lhs3.Contains(7)); Assert.IsTrue(lhs3.Contains(0)); Assert.AreEqual(lhs3.Count, 10); #endregion #region IntersectWith lhs1 = new LinkedHashSet <int>(set1); lhs2 = new LinkedHashSet <int>(set2); lhs3 = new LinkedHashSet <int>(set3); lhs1.IntersectWith(lhs2); Assert.IsTrue(lhs1.SetEquals(set2)); lhs3.IntersectWith(lhs2); Assert.IsTrue(lhs3.SetEquals(set2)); lhs1 = new LinkedHashSet <int>(set1); lhs2 = new LinkedHashSet <int>(set2); lhs3 = new LinkedHashSet <int>(set3); lhs3.IntersectWith(lhs1); Assert.IsFalse(lhs3.Contains(7)); Assert.IsFalse(lhs3.Contains(0)); Assert.AreEqual(lhs3.Count, 8); Assert.IsTrue(lhs3.SetEquals(set2)); #endregion #region SymmetricExceptWith lhs1 = new LinkedHashSet <int>(set1); lhs2 = new LinkedHashSet <int>(set2); lhs3 = new LinkedHashSet <int>(set3); lhs1.SymmetricExceptWith(lhs3); Assert.AreEqual(lhs1.Count, 2); Assert.IsTrue(lhs1.Contains(0)); Assert.IsTrue(lhs1.Contains(7)); lhs1.SymmetricExceptWith(lhs2); Assert.AreEqual(lhs1.Count, 10); #endregion LinkedHashSet <int> lhs = new LinkedHashSet <int>(); for (int i = 0; i < set1.Length; i++) { lhs.Add(set1[i]); } List <int> set1a = new List <int>(); foreach (var i in lhs) { set1a.Add(i); } for (int i = 0; i < set1.Length; i++) { Assert.AreEqual(set1[i], set1a[i]); } lhs.Remove(7); lhs.Add(0); set1a.Clear(); foreach (var i in lhs) { set1a.Add(i); } for (int i = 0; i < set3.Length; i++) { Assert.AreEqual(set3[i], set1a[i]); } }