What is the best way of checking the matrix value in Unit test?

非 Y 不嫁゛ 提交于 2019-12-06 14:41:25

There is no built-in solution in MsTest BCL for comparing matrices. However there are several overloads which allows you to compare using a custom IComparer:(BTW CollectionAssert use those overloads internally...)

class CollectionAssertComperator : IComparer
{
    public int Compare(object x, object y)
    {
        CollectionAssert.AreEqual((ICollection)x, (ICollection)y);
        return 0;
    }
}

Then you can simply use it:(and it is a reusable solution)

CollectionAssert.AreEqual(correct, result, new CollectionAssertComperator());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!