这是单元测试的第一次尝试。我的.Equals
方法在TestSet_Equals_True
,上失败了TestSet_Equals_True_Shuffled_Order
。希望澄清这是否是我的单元测试的问题还是我的.Equals
方法有问题。
单元测试:
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);
}
班级:
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); }