Code Coverage: (bc: block coverage)
Factory Method:
[PexFactoryMethod(typeof(DataStructures.Stack<int>))]public static DataStructures.Stack<int> Create(int[] elems){ PexAssume.IsTrue(elems != null && elems.Length < 11); PexAssume.TrueForAll(0, elems.Length, _i => elems[_i] > -11 && elems[_i] < 11); DataStructures.Stack<int> ret = new DataStructures.Stack<int>(elems.Length+2 ); for (int i = 0; i < elems.Length; i++) { // For stack, add any element. ret.Push(elems[i]); } return ret;}
Equal Method:
public string ToStringForInts(){ /* It happens that this implementation of stack keeps the top item at end of array*/ string ret = "{"; for (int i = 0; i < _size; i++) { ret += _array[i].ToString()+" "; } return ret + "}"; }
public class StackEqualityComparer : EqualityComparer<Stack<int>>{ public override bool Equals(DataStructures.Stack<int> s1, DataStructures.Stack<int> s2) { if (s1 == null || s2 == null) return false; return s1.ToStringForInts().Equals(s2.ToStringForInts()); } public override int GetHashCode(DataStructures.Stack<int> s) { int hash = 0; int[] sArray = s.ToArray(); for (int i = 0; i < sArray.Length; i++) { hash += i * sArray[i]; } return hash; }}
Clone Method:
public virtual Object Clone(){ Stack<int> s = new Stack<int>(_size); s._size = _size; Array.Copy(_array, 0, s._array, 0, _size); s._version = _version; return s;}