List of usage examples for org.apache.commons.math.util MathUtils equals
public static boolean equals(double[] x, double[] y)
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MgfParserTest.java
@Test(groups = "unit") public void testMrrConvertedByTpp() { final InputStream inputStream = ProteomicsTests.getResourceAsStream("readw.mgf-shortened"); final Iterator<Scan> scanIter = new MgfParser().parserMgf(inputStream); final Scan scan1 = scanIter.next(); assert scan1.getNumber() == 78 : scan1.getNumber(); assert scan1.getMsLevel() == 2; assert scan1.getPrecursorCharge() == 2; assert MathUtils.equals(scanIter.next().getPeaks()[0], 221.161362d); final int expectedNumScans = 4; int numScans = 2; while (scanIter.hasNext()) { scanIter.next();/*from www . j av a 2 s . c o m*/ numScans++; } assert numScans == expectedNumScans : numScans; }
From source file:edu.umn.msi.tropix.common.test.FloatingPointDataStreamTest.java
@Test(groups = "unit") public void readDouble() throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // final DataOutputStream dos = new DataOutputStream(bos); final FloatingPointDataOutputStream dos = new FloatingPointDataOutputStream(bos); dos.writeDouble(123.45d);//w w w .j a v a 2s. c o m dos.writeFloat(12.3f); bos.close(); final InputStream ds = new ByteArrayInputStream(bos.toByteArray()); final FloatingPointDataInputStream fis = new FloatingPointDataInputStream(ds); final double d1 = fis.readDouble(); final float f1 = fis.readFloat(); assert MathUtils.equals(123.45, d1); assert MathUtils.equals(f1, 12.3f); }
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToDTAConverterStreamingImplTest.java
@Test(groups = "unit") public void readw() { /*/*from www. j a va 2 s . co m*/ final Random random = new Random(); int count = 5000; double[] peaks = new double[count]; for(int i =0; i < count; i++) { peaks[i] = random.nextDouble(); } System.out.println(new String(Base64.encodeBase64(ConversionUtils.doubles2bytes(peaks)))); */ final MzXMLToDTAConverterStreamingImpl converter = new MzXMLToDTAConverterStreamingImpl(); DTAList dtaList; InputStream mzxmlStream; mzxmlStream = ProteomicsTests.getResourceAsStream("readw.mzXML"); try { dtaList = converter.mzxmlToDTA(mzxmlStream, null); double[] contents78charge2 = null, contents78charge3 = null; for (DTAList.Entry entry : dtaList) { if (entry.getName().matches(".*0*78\\.0*78\\.2\\.dta$")) { assert contents78charge2 == null; contents78charge2 = DTAUtils.readDtaDoublePairs(entry.getContents()); } if (entry.getName().matches(".*0*78\\.0*78\\.3\\.dta$")) { assert contents78charge3 == null; contents78charge3 = DTAUtils.readDtaDoublePairs(entry.getContents()); } if (entry.getName().matches(".*0*1993\\.0*1993\\.1\\.dta$")) { final double[] values = DTAUtils.readDtaDoublePairs(entry.getContents()); final Scanner scanner = new Scanner(new ByteArrayInputStream(entry.getContents())); assert MathUtils.equals(scanner.nextDouble(), 1515.390000); assert scanner.nextInt() == 1; assert Math.abs(662.267334 - values[0]) < .01 : values[0]; assert Math.abs(4.004042 - values[values.length - 1]) < .01; } } assert contents78charge2 != null; assert contents78charge3 != null; assert contents78charge2.length == contents78charge3.length; for (int i = 2; i < contents78charge2.length; i++) { assert MathUtils.equals(contents78charge2[i], contents78charge3[i]); } } finally { IO_UTILS.closeQuietly(mzxmlStream); } }