OutputStream stream = new FileOutputStream(testFile);
testData.serialize(stream);
stream.flush();
stream.close();
SegmentedChromosomeData copy = new SegmentedChromosomeData();
InputStream is = new FileInputStream(testFile);
copy.deserialize(is);
is.close();
String[] expectedSamples = testData.getSampleNames();
String[] samples = copy.getSampleNames();
assertEquals(expectedSamples.length, samples.length);
for (int i = 0; i < samples.length; i++) {
assertEquals(expectedSamples[i], samples[i]);
}
for (String s : samples) {
int[] expectedStarts = testData.getStartLocations(s);
int[] starts = copy.getStartLocations(s);
assertEquals(expectedStarts.length, starts.length);
for (int i = 0; i < starts.length; i++) {
assertEquals(expectedStarts[i], starts[i]);
}
int[] expectedEnds = testData.getEndLocations(s);
int[] ends = copy.getEndLocations(s);
assertEquals(expectedEnds.length, ends.length);
for (int i = 0; i < starts.length; i++) {
assertEquals(expectedEnds[i], ends[i]);
}
float[] expectedValues = testData.getValues(s);
float[] values = copy.getValues(s);
assertEquals(values.length, values.length);
for (int i = 0; i < starts.length; i++) {
assertEquals(expectedValues[i], values[i], 1.0e-6);
}
}