Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

=+How effective is the adjustment letter?

Answered: 1 week ago