public void testToBigDecimal() throws Exception { BigDecimal [] decimals = {new BigDecimal("-1"), new BigDecimal("123.123"), new BigDecimal("123123123123")}; for (int i = 0; i < decimals.length; i++) { byte [] b = Bytes.toBytes(decimals[i]); assertEquals(decimals[i], Bytes.toBigDecimal(b)); byte [] b2 = bytesWithOffset(b); assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length)); } }
public void testReadAsVLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(baos); WritableUtils.writeVLong(output, longs[i]); byte[] long_bytes_no_offset = baos.toByteArray(); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_no_offset, 0)); byte[] long_bytes_with_offset = bytesWithOffset(long_bytes_no_offset); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_with_offset, 1)); } }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }
public void testToDouble() throws Exception { double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; for (int i = 0; i < doubles.length; i++) { byte [] b = Bytes.toBytes(doubles[i]); assertEquals(doubles[i], Bytes.toDouble(b), 0.0); byte [] b2 = bytesWithOffset(b); assertEquals(doubles[i], Bytes.toDouble(b2, 1), 0.0); } }
public void testToLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { byte [] b = Bytes.toBytes(longs[i]); assertEquals(longs[i], Bytes.toLong(b)); byte [] b2 = bytesWithOffset(b); assertEquals(longs[i], Bytes.toLong(b2, 1)); assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); } }
public void testToInt() throws Exception { int [] ints = {-1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE}; for (int i = 0; i < ints.length; i++) { byte [] b = Bytes.toBytes(ints[i]); assertEquals(ints[i], Bytes.toInt(b)); byte [] b2 = bytesWithOffset(b); assertEquals(ints[i], Bytes.toInt(b2, 1)); assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT)); } }
public void testToBigDecimal() throws Exception { BigDecimal [] decimals = {new BigDecimal("-1"), new BigDecimal("123.123"), new BigDecimal("123123123123")}; for (int i = 0; i < decimals.length; i++) { byte [] b = Bytes.toBytes(decimals[i]); assertEquals(decimals[i], Bytes.toBigDecimal(b)); byte [] b2 = bytesWithOffset(b); assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length)); } }
public void testToBigDecimal() throws Exception { BigDecimal [] decimals = {new BigDecimal("-1"), new BigDecimal("123.123"), new BigDecimal("123123123123")}; for (int i = 0; i < decimals.length; i++) { byte [] b = Bytes.toBytes(decimals[i]); assertEquals(decimals[i], Bytes.toBigDecimal(b)); byte [] b2 = bytesWithOffset(b); assertEquals(decimals[i], Bytes.toBigDecimal(b2, 1, b.length)); } }
public void testReadAsVLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(baos); WritableUtils.writeVLong(output, longs[i]); byte[] long_bytes_no_offset = baos.toByteArray(); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_no_offset, 0)); byte[] long_bytes_with_offset = bytesWithOffset(long_bytes_no_offset); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_with_offset, 1)); } }
public void testReadAsVLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(baos); WritableUtils.writeVLong(output, longs[i]); byte[] long_bytes_no_offset = baos.toByteArray(); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_no_offset, 0)); byte[] long_bytes_with_offset = bytesWithOffset(long_bytes_no_offset); assertEquals(longs[i], Bytes.readAsVLong(long_bytes_with_offset, 1)); } }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }
public void testToFloat() throws Exception { float [] floats = {-1f, 123.123f, Float.MAX_VALUE}; for (int i = 0; i < floats.length; i++) { byte [] b = Bytes.toBytes(floats[i]); assertEquals(floats[i], Bytes.toFloat(b), 0.0f); byte [] b2 = bytesWithOffset(b); assertEquals(floats[i], Bytes.toFloat(b2, 1), 0.0f); } }
public void testToDouble() throws Exception { double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; for (int i = 0; i < doubles.length; i++) { byte [] b = Bytes.toBytes(doubles[i]); assertEquals(doubles[i], Bytes.toDouble(b), 0.0); byte [] b2 = bytesWithOffset(b); assertEquals(doubles[i], Bytes.toDouble(b2, 1), 0.0); } }
public void testToDouble() throws Exception { double [] doubles = {Double.MIN_VALUE, Double.MAX_VALUE}; for (int i = 0; i < doubles.length; i++) { byte [] b = Bytes.toBytes(doubles[i]); assertEquals(doubles[i], Bytes.toDouble(b), 0.0); byte [] b2 = bytesWithOffset(b); assertEquals(doubles[i], Bytes.toDouble(b2, 1), 0.0); } }
public void testToInt() throws Exception { int [] ints = {-1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE}; for (int i = 0; i < ints.length; i++) { byte [] b = Bytes.toBytes(ints[i]); assertEquals(ints[i], Bytes.toInt(b)); byte [] b2 = bytesWithOffset(b); assertEquals(ints[i], Bytes.toInt(b2, 1)); assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT)); } }
public void testToLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { byte [] b = Bytes.toBytes(longs[i]); assertEquals(longs[i], Bytes.toLong(b)); byte [] b2 = bytesWithOffset(b); assertEquals(longs[i], Bytes.toLong(b2, 1)); assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); } }
public void testToInt() throws Exception { int [] ints = {-1, 123, Integer.MIN_VALUE, Integer.MAX_VALUE}; for (int i = 0; i < ints.length; i++) { byte [] b = Bytes.toBytes(ints[i]); assertEquals(ints[i], Bytes.toInt(b)); byte [] b2 = bytesWithOffset(b); assertEquals(ints[i], Bytes.toInt(b2, 1)); assertEquals(ints[i], Bytes.toInt(b2, 1, Bytes.SIZEOF_INT)); } }
public void testToLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { byte [] b = Bytes.toBytes(longs[i]); assertEquals(longs[i], Bytes.toLong(b)); byte [] b2 = bytesWithOffset(b); assertEquals(longs[i], Bytes.toLong(b2, 1)); assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); } }