H
harryos
hi,
I am writing some code that manipulates some matrices and arrays of
double type.I wanted to write some junit testcases for the code.
suppose I have a method that does some calculation on a 2D array and
returns another 2D array.
public class MatrixManipulator{
....
public double[][] calculateNewMatrix(double[][] originalMatrix){
...
}
....
}
I wanted to put all the test data in a single class ,say MatrixData,
I wrote the testcase as below,
public class MatrixTests{
private double[][] origMatrix;
private double[][] finalMatrix;
private MatrixManipulator mat;
@Before
public void setUp(){
mat = new MatrixManipulator();
MatrixData mData = new MatrixData();
origMatrix = mData.getOrigMatrix();
finalMatrix = mData.getFinalMatrix();
}
@test
public void testCalculateNewMatrix(){
double[][] result = mat.calculateNewMatrix(origMatrix);
for(int i = 0; i< result.length; i++){
Assert.assertArrayEquals(finalMatrix, result,
0.0001);
}
}
}
I wanted to know if this is the proper way of accessing test data and
testing array equality.Any comments/opinions/suggestions most welcome.
thanks,
harry
I am writing some code that manipulates some matrices and arrays of
double type.I wanted to write some junit testcases for the code.
suppose I have a method that does some calculation on a 2D array and
returns another 2D array.
public class MatrixManipulator{
....
public double[][] calculateNewMatrix(double[][] originalMatrix){
...
}
....
}
I wanted to put all the test data in a single class ,say MatrixData,
I wrote the testcase as below,
public class MatrixTests{
private double[][] origMatrix;
private double[][] finalMatrix;
private MatrixManipulator mat;
@Before
public void setUp(){
mat = new MatrixManipulator();
MatrixData mData = new MatrixData();
origMatrix = mData.getOrigMatrix();
finalMatrix = mData.getFinalMatrix();
}
@test
public void testCalculateNewMatrix(){
double[][] result = mat.calculateNewMatrix(origMatrix);
for(int i = 0; i< result.length; i++){
Assert.assertArrayEquals(finalMatrix, result,
0.0001);
}
}
}
I wanted to know if this is the proper way of accessing test data and
testing array equality.Any comments/opinions/suggestions most welcome.
thanks,
harry