This is first attempt at unit testing. My .Equals method is failing on TestSet_Equals_True, TestSet_Equals_True_Shuffled_Order. Hoping for clarification as to whether this is a problem with HOW I Unit test or something is wrong with my .Equals method.
Unit Test:
private void Populate(Set set, int count)
{
for (int i = 0; i < count; ++i)
set.Add(i);
}
[TestMethod]
public void TestSet_Equals_True()
{
Set set1 = new Set();
Set set2 = new Set();
Populate(set1, POPULATE_COUNT);
Populate(set2, POPULATE_COUNT);
bool expected = true;
bool actual = set1.Equals(set2);
Assert.AreEqual(expected, actual);
}
Class:
List<object> _set;
//Override Equals
public override bool Equals(object obj)
{
if (this.GetType() != obj.GetType())
return false;
Set o = (Set)obj;
if (this._set.Count != o._set.Count)
return false;
o._set.Sort();
this._set.Sort();
return _set.Equals(o._set); }
List<T>implementation of Equals is the default implementation ofobject.Equals– Reference Equality.To see if two
IEnumerable<T>are equal, You can use the extension methodIEnumerable<T>.SequenceEquals– Don’t forget to addusingstatement forSystem.Linqnamespace.Good luck.