use of org.codice.ddf.libs.klv.data.numerical.KlvDouble in project ddf by codice.
the class KlvDecoderTest method testDoubleValue.
@Test
public void testDoubleValue() throws KlvDecodingException {
final byte[] klvBytes = { -8, 8, 0x40, (byte) 0xD5, 0x0F, (byte) 0xCB, 0x21, 0x07, (byte) 0xB7, (byte) 0x84 };
final KlvDouble klvDouble = new KlvDouble(new byte[] { -8 }, "test");
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvDouble, klvBytes);
final double value = ((KlvDouble) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(21567.173891));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvDouble in project ddf by codice.
the class KlvContextTest method testAddDataElementCollection.
@Test
public void testAddDataElementCollection() {
final KlvContext klvContext = new KlvContext(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE);
final Collection<KlvDataElement> dataElements = new HashSet<>();
final KlvInt klvInt = new KlvInt(new byte[] { 1 }, "first");
dataElements.add(klvInt);
final KlvDouble klvDouble = new KlvDouble(new byte[] { 2 }, "second");
dataElements.add(klvDouble);
klvContext.addDataElements(dataElements);
verifyKLVContextDataElements(klvContext, klvInt, klvDouble);
}
use of org.codice.ddf.libs.klv.data.numerical.KlvDouble in project ddf by codice.
the class KlvDecoderTest method isErrorIndicatedDouble.
private boolean isErrorIndicatedDouble(double value, Optional<Double> errorValue) throws KlvDecodingException {
KlvDouble klvDouble = new KlvDouble(new byte[] { 0 }, "test", errorValue);
byte[] dataBytes = new byte[10];
dataBytes[0] = 0;
dataBytes[1] = 8;
arraycopy(longToBytes(Double.doubleToLongBits(value)), 0, dataBytes, 2, 8);
return isErrorIndicatedDecode(klvDouble, dataBytes);
}