2012-11-02 42 views
3

我有一個手動提取日期的函數。如果兩個鋸齒狀數組相等,你如何進行單元測試?

[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.通過瀏覽,我意識到返回數組是可變的,這不是一個好習慣。但我仍然想知道如何測試這不是使用循環來斷言數組中的每個元素。

+0

旁註:這裏有一個更簡單的填充期望值方式:'VAR預期=新[] {新的[] {6,2,2012},新[] {12,10,2012}};'。 –

+0

從技術上講,你擁有的是一個數組數組,或一個鋸齒狀數組,而不是一個二維數組。二維數組將是'int [,]'。 –

+0

感謝您的有用提示! :D – Henry

回答

相關問題