我有一個手動提取日期的函數。如果兩個鋸齒狀數組相等,你如何進行單元測試?
[TestMethod]
public void TestRemoveTwoDates()
{
String test = "at 06/2/2012 to 12/10/2012";
int[][] actual = String_Parser.RemoveTwoDates(test, "to");
int[][] expected = new int[2][];
expected[0] = new int[3] { 6, 2, 2012 };
expected[1] = new int[3] { 12, 10, 2012 };
CollectionAssert.AreEqual(expected, actual);
}
P.S.通過瀏覽,我意識到返回數組是可變的,這不是一個好習慣。但我仍然想知道如何測試這不是使用循環來斷言數組中的每個元素。
旁註:這裏有一個更簡單的填充期望值方式:'VAR預期=新[] {新的[] {6,2,2012},新[] {12,10,2012}};'。 –
從技術上講,你擁有的是一個數組數組,或一個鋸齒狀數組,而不是一個二維數組。二維數組將是'int [,]'。 –
感謝您的有用提示! :D – Henry