Code Coverage: (bc: block coverage)
Factory Method:
public static DataStructures.HashSet<int> Create(int[] elems){ PexAssume.IsTrue(elems != null && elems.Length < 11); PexAssume.TrueForAll(0, elems.Length, _i => elems[_i] > -11 && elems[_i] < 11); DataStructures.HashSet<int> ret = new DataStructures.HashSet<int>(elems.Length + 2);// DataStructure has big enough capacity for Commutativity Test for (int i = 0; i < elems.Length; i++) { //PexAssume.IsTrue(elems[i] > -101 && elems[i] < 101); if(!ret.Contains(elems[i])) ret.Add(elems[i]); } return ret;}
Equal Method:
public string ToStringForInt(){ //Assumes T(int) has ToString() string ret = "{"; /*for (int i = 0; i < _count; i++) { ret += _slots[i].value.ToString() + " "; }*/ foreach (var item in this) { ret += item.ToString() + " "; } return ret + "}"; }
public sealed class HashSetEqualityComparer<T> : IEqualityComparer<HashSet<T>>{ private readonly IEqualityComparer<T> m_comparer; public HashSetEqualityComparer() { m_comparer = EqualityComparer<T>.Default; } // using m_comparer to keep equals properties in tact; don't want to choose one of the comparers public bool Equals(HashSet<T> x, HashSet<T> y) { // return HashSet<T>.HashSetEquals(x, y, m_comparer); return x.SetEquals(y); } public int GetHashCode(HashSet<T> obj) { int hashCode = 0; if (obj != null) { foreach (T t in obj) { hashCode = hashCode ^ (m_comparer.GetHashCode(t) & 0x7FFFFFFF); } } // else returns hashcode of 0 for null hashsets return hashCode; } // Equals method for the comparer itself. public override bool Equals(object obj) { HashSetEqualityComparer<T> comparer = obj as HashSetEqualityComparer<T>; if (comparer == null) { return false; } return (m_comparer == comparer.m_comparer); } public override int GetHashCode() { return m_comparer.GetHashCode(); }}