Ejemplo n.º 1
0
  public void testReadSwappedDouble() throws IOException {
    byte[] bytes = new byte[] {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
    double d1 = Double.longBitsToDouble(0x0102030405060708L);
    double d2 = EndianUtils.readSwappedDouble(bytes, 0);
    assertEquals(d1, d2, 0.0);

    ByteArrayInputStream input = new ByteArrayInputStream(bytes);
    assertEquals(d1, EndianUtils.readSwappedDouble(input), 0.0);
  }
Ejemplo n.º 2
0
 public void testEOFException() throws IOException {
   ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {});
   try {
     EndianUtils.readSwappedDouble(input);
     fail("Expected EOFException");
   } catch (EOFException e) {
     // expected
   }
 }
Ejemplo n.º 3
0
  // tests #IO-101
  public void testSymmetryOfLong() {

    double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
    for (int i = 0; i < tests.length; i++) {

      // testing the real problem
      byte[] buffer = new byte[8];
      long ln1 = Double.doubleToLongBits(tests[i]);
      EndianUtils.writeSwappedLong(buffer, 0, ln1);
      long ln2 = EndianUtils.readSwappedLong(buffer, 0);
      assertEquals(ln1, ln2);

      // testing the bug report
      buffer = new byte[8];
      EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
      double val = EndianUtils.readSwappedDouble(buffer, 0);
      assertEquals(tests[i], val, 0);
    }
  }
Ejemplo n.º 4
0
  // tests #IO-101
  @Test
  public void testSymmetryOfLong() {

    final double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
    for (final double test : tests) {

      // testing the real problem
      byte[] buffer = new byte[8];
      final long ln1 = Double.doubleToLongBits(test);
      EndianUtils.writeSwappedLong(buffer, 0, ln1);
      final long ln2 = EndianUtils.readSwappedLong(buffer, 0);
      assertEquals(ln1, ln2);

      // testing the bug report
      buffer = new byte[8];
      EndianUtils.writeSwappedDouble(buffer, 0, test);
      final double val = EndianUtils.readSwappedDouble(buffer, 0);
      assertEquals(test, val, 0);
    }
  }