public void ForEachWithConditionTest2() { RectMatrix <int, int> matrix = new RectMatrix <int, int>(); matrix.EnsureSize(3, 2); matrix[0, 0] = 2; matrix[0, 1] = 7; matrix[1, 0] = 9; matrix[1, 1] = 0; matrix[2, 0] = 1; matrix[2, 1] = 2; matrix.RowAttributes[0] = 1; matrix.RowAttributes[1] = 2; matrix.RowAttributes[2] = 3; matrix.ColumnAttributes[0] = 4; matrix.ColumnAttributes[1] = 5; List <int> rowIndexList1 = new List <int>(); List <int> rowIndexList2 = new List <int>(); List <int> columnIndexList1 = new List <int>(); List <int> columnIndexList2 = new List <int>(); matrix.ForEach((row, column, rowAttribute, columnAttribute, x) => { rowIndexList1.Add(row); columnIndexList1.Add(column); return(rowAttribute == 2); }, (row, column, x) => { rowIndexList2.Add(row); columnIndexList2.Add(column); }); CollectionAssert.AreEqual(new int[] { 0, 0, 1, 1, 2, 2 }, rowIndexList1); CollectionAssert.AreEqual(new int[] { 0, 1, 0, 1, 0, 1 }, columnIndexList1); CollectionAssert.AreEqual(new int[] { 1, 1 }, rowIndexList2); CollectionAssert.AreEqual(new int[] { 0, 1 }, columnIndexList2); }
public void ForEachWithConditionTest1() { RectMatrix <int, int> matrix = new RectMatrix <int, int>(); matrix.EnsureSize(4, 3); matrix[0, 0] = 7; matrix[0, 1] = 2; matrix[0, 2] = 3; matrix[1, 0] = 4; matrix[1, 1] = 2; matrix[1, 2] = 9; matrix[2, 0] = 3; matrix[2, 1] = 7; matrix[2, 2] = 6; matrix[3, 0] = 9; matrix[3, 1] = 1; matrix[3, 2] = 0; matrix.RowAttributes[0] = 1; matrix.RowAttributes[1] = 2; matrix.RowAttributes[2] = 3; matrix.RowAttributes[3] = 4; matrix.ColumnAttributes[0] = 5; matrix.ColumnAttributes[1] = 6; matrix.ColumnAttributes[2] = 7; List <int> itemList = new List <int>(); matrix.ForEach((row, column, rowAttribute, columnAttribute, x) => rowAttribute > 1 && rowAttribute < 4 && columnAttribute > 5, (row, column, x) => itemList.Add(x)); CollectionAssert.AreEqual(new int[] { 2, 9, 7, 6 }, itemList); }
public void ForEachWithConditionGuardCase2Test() { RectMatrix <int, int> matrix = new RectMatrix <int, int>(); matrix.EnsureSize(1, 1); matrix[0, 0] = 1; matrix.ForEach((row, column, rowAttribute, columnAttribute, x) => true, null); }
public void ForEachWithConditionGuardCase1Test() { RectMatrix <int, int> matrix = new RectMatrix <int, int>(); matrix.EnsureSize(1, 1); matrix[0, 0] = 1; matrix.ForEach(null, (row, column, x) => { }); }
public void ForEachTest() { RectMatrix <string> matrix = new RectMatrix <string>(); matrix.EnsureSize(2, 3); matrix[0, 0] = "F"; matrix[0, 1] = "X"; matrix[0, 2] = "7"; matrix[1, 0] = "ABC"; matrix[1, 1] = "N"; matrix[1, 2] = "P"; List <string> list = new List <string>(); matrix.ForEach(x => list.Add(x)); CollectionAssert.AreEqual(new string[] { "F", "X", "7", "ABC", "N", "P" }, list); }
public void ForEachGuardTest() { RectMatrix <string> matrix = new RectMatrix <string>(); matrix.ForEach(null); }