Search in sources :

Example 1 with KlvDouble

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));
}
Also used : KlvDouble(org.codice.ddf.libs.klv.data.numerical.KlvDouble) Test(org.junit.Test)

Example 2 with KlvDouble

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);
}
Also used : KlvDouble(org.codice.ddf.libs.klv.data.numerical.KlvDouble) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with 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);
}
Also used : KlvDouble(org.codice.ddf.libs.klv.data.numerical.KlvDouble)

Aggregations

KlvDouble (org.codice.ddf.libs.klv.data.numerical.KlvDouble)3 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)1