Ejemplo n.º 1
0
  public void testWriteSwappedDouble() throws IOException {
    byte[] bytes = new byte[8];
    double d1 = Double.longBitsToDouble(0x0102030405060708L);
    EndianUtils.writeSwappedDouble(bytes, 0, d1);
    assertEquals(0x08, bytes[0]);
    assertEquals(0x07, bytes[1]);
    assertEquals(0x06, bytes[2]);
    assertEquals(0x05, bytes[3]);
    assertEquals(0x04, bytes[4]);
    assertEquals(0x03, bytes[5]);
    assertEquals(0x02, bytes[6]);
    assertEquals(0x01, bytes[7]);

    ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
    EndianUtils.writeSwappedDouble(baos, d1);
    bytes = baos.toByteArray();
    assertEquals(0x08, bytes[0]);
    assertEquals(0x07, bytes[1]);
    assertEquals(0x06, bytes[2]);
    assertEquals(0x05, bytes[3]);
    assertEquals(0x04, bytes[4]);
    assertEquals(0x03, bytes[5]);
    assertEquals(0x02, bytes[6]);
    assertEquals(0x01, bytes[7]);
  }
Ejemplo n.º 2
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.º 3
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);
    }
  }