@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Value)) { return false; } Value v = (Value) o; if (!v.isFloatValue()) { return false; } return value == v.asFloatValue().toFloat(); }
@Test public void testOrdinaryFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345.12"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); }
@Test public void testExponentialFloat() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("1.234512E4"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345.12, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12345.12", msgpackValue.asFloatValue().toString()); } }
@Test public void testExponentialInteger1() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345e3"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345000.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("1.2345E7", msgpackValue.asFloatValue().toString()); }
@Test public void testExponentialInteger2() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("123e2"); assertTrue(msgpackValue.getValueType().isNumberType()); // TODO: Consider this needs to be an integer? // See: https://github.com/embulk/embulk/issues/775 assertTrue(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12300.0, msgpackValue.asFloatValue().toDouble(), 0.000000001); // Not sure this |toString| is to be tested... assertEquals("12300.0", msgpackValue.asFloatValue().toString()); }
@Override public Float deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asFloatValue().toFloat(); } }
@Override public Double deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asFloatValue().toDouble(); } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Value)) { return false; } Value v = (Value) o; if (!v.isFloatValue()) { return false; } return value == v.asFloatValue().toDouble(); }
private Object value(Value value) { switch (value.getValueType()) { case NIL: return null; case BOOLEAN: return value.asBooleanValue().getBoolean(); case INTEGER: return value.asIntegerValue().toLong(); case FLOAT: return value.asFloatValue().toFloat(); case STRING: return value.asStringValue().toString(); case BINARY: case ARRAY: case MAP: case EXTENSION: default: throw new UnsupportedOperationException("Unsupported column type: " + value.getValueType()); } } }
assertEquals(1.23, val.asFloatValue().toFloat(), 0.000001);