Why does Assert.AreEqual(T obj1, Tobj2) fail with identical byte arrays

前端 未结 6 2015
日久生厌
日久生厌 2021-02-03 16:56

I have two identical byte arrays in the following segment of code:

    /// 
    ///A test for Bytes
    ///
    [TestMethod()]
            


        
6条回答
  •  逝去的感伤
    2021-02-03 17:16

    Created simple helper method:

    private static void CompareArrays(T[] expected, T[] actual)
    {
        Assert.AreEqual(expected == null, actual == null, "Expected {0}null value and {1}null found.", expected == null ? "" : "not", actual == null ? "" : "not");
        if (expected == null || actual == null)
                return;
    
        Assert.AreEqual(expected.LongLength, actual.LongLength, "Expected Length is {0} actual: {1}", expected.LongLength, actual.LongLength);
    
        for (int i = 0; i < expected.Length; i++)
        {
            Assert.AreEqual(expected[i], actual[i], "Values on index {0} are not equal. Expected {1} actual: {2}", i, expected[i], actual[i]);
        }
    }
    

提交回复
热议问题