@Test public void testFloat() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeFloat(random.nextFloat()); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextFloat(), in.readFloat(), 0); }
writeFixed64((Long)value); break; case FLOAT: writeFloat((Float)value); break; case DOUBLE: writeDouble((Double)value); break;
@Test public void testFloat() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeFloat(random.nextFloat()); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextFloat(), in.readFloat(), 0); }
public void writeValue(Object value, ValueType type) throws IOException { switch (type) { case NULL: break; case INT: writeInt((Integer)value); break; case LONG: writeLong((Long)value); break; case FIXED32: writeFixed32((Integer)value); break; case FIXED64: writeFixed64((Long)value); break; case FLOAT: writeFloat((Float)value); break; case DOUBLE: writeDouble((Double)value); break; case STRING: writeString((String)value); break; case BYTES: if (value instanceof ByteBuffer) writeBytes((ByteBuffer)value); else writeBytes((byte[])value); break; default: throw new TrevniRuntimeException("Unknown value type: "+type); } }