예제 #1
0
  public void testReadSwappedLong() throws IOException {
    byte[] bytes = new byte[] {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
    assertEquals(0x0102030405060708L, EndianUtils.readSwappedLong(bytes, 0));

    ByteArrayInputStream input = new ByteArrayInputStream(bytes);
    assertEquals(0x0102030405060708L, EndianUtils.readSwappedLong(input));
  }
예제 #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);
    }
  }
예제 #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);
    }
  }