【发布时间】:2018-04-12 13:02:59
【问题描述】:
在测试这段代码时:
public static int maxRowAbsSum(int[][] array) {
int[][] maxRowValue = {
{3, -1, 4, 0},
{5, 9, -2, 6},
{5, 3, 7, -8}
};
int maxRow = 0;
int indexofMaxRow = 0;
for (int row = 0; row < maxRowValue.length; row++) {
int totalOfRow = 0;
for (int column = 0; column < maxRowValue[row].length; column++){
if (maxRowValue[row][column] > 0) {
totalOfRow += maxRowValue[row][column];
} else {
totalOfRow -= maxRowValue[row][column];
}
}
if (totalOfRow > maxRow) {
maxRow = totalOfRow;
indexofMaxRow = row;
}
}
System.out.println("Row " + indexofMaxRow + " has the sum of " + maxRow);
return indexofMaxRow;
}
使用这个 JUnit 代码:
@Test
public void maxRowAbsSum() {
int [] i = new int [] {};
assertArrayEquals(i, Exercise2.maxRowAbsSum(numArray));
}
这在红色下划线 assertArrayEquals 说:
Assert 类型中的方法assertArrayEquals(int[], int[]) 不适用于参数(int[], int)
我写错了吗?如何使用 JUnit 对其进行测试,使其没有错误或故障?
【问题讨论】: