Question: Wouldn't pass the test case /** * Test the writeToFile method * write the array to the outputFile File * then read it back to

Wouldn't pass the test case

/**

* Test the writeToFile method

* write the array to the outputFile File

* then read it back to make sure formatted correctly to read

*

*/

@Test

public void testWriteToFile() {

double[][] array=null;

try {

TwoDimRaggedArrayUtility.writeToFile(dataSet4, outputFile);

} catch (Exception e) {

fail("This should not have caused an Exception");

}

//now read from the output file

try {

array = TwoDimRaggedArrayUtility.readFile(outputFile);

assertEquals(-2.5, array[0][0],.001);

assertEquals(-5.3, array[0][1],.001);

assertEquals(6.1, array[0][2],.001);

assertEquals(-4.4, array[1][0],.001);

assertEquals(8.2, array[1][1],.001);

assertEquals(2.3, array[2][0],.001);

assertEquals(-7.5, array[2][1],.001);

assertEquals(-4.2, array[3][0],.001);

assertEquals(7.3, array[3][1],.001);

assertEquals(-5.9, array[3][2],.001);

assertEquals(2.6, array[3][3],.001);

} catch (FileNotFoundException e) {

fail("This should not have caused an Exception");

}

}

_______________________________________________________________________

public static void writeToFile(double[][] arr, File file){ try { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); for(int i = 0; i < arr.length; ++i){ for(int j = 0; j < arr[i].length; ++j){ bw.write(arr[i][j] + " "); } bw.write(" "); } bw.close(); } catch (IOException e) { e.printStackTrace(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!