@Test
public void testWriteMatrixToCSVFile() throws IOException {

    DenseMatrix matrix = new DenseMatrix(MathTestConstants.STORAGE_SIZE, MathTestConstants.STORAGE_SIZE);
    for (int i = 0; i < matrix.rowSize(); i++)
        for (int j = 0; j < matrix.columnSize(); j++)
            matrix.set(i, j, Math.random());
    Path file = createTempFile("matrix", ".csv");
    Tracer.saveAsCsv(matrix, DEFAULT_FORMAT, file.toString());
    System.out.println("Matrix exported: " + file.getFileName());
    List<String> strings = Files.readAllLines(file);
    Optional<String> reduce = strings.stream().reduce((s1, s2) -> s1 + s2);
    String[] csvVals = reduce.orElse("").split(",");
    for (int i = 0; i < matrix.rowSize(); i++)
        for (int j = 0; j < matrix.columnSize(); j++) {
            Double csvVal = Double.valueOf(csvVals[i * matrix.rowSize() + j]);
            assertEquals("Unexpected value.", csvVal, matrix.get(i, j), DEFAULT_DELTA);
        }
    Files.deleteIfExists(file);
}