function testEncodeVarintFloat() { foreach ($this->tests as $i => $enc) { if (!hasExactRepresentation($i) || $i < 0) { continue; } if (is_string($i)) { $i = (double) $i; } $result = Protobuf::encode_varint_float($i); $this->assertBinaryEqual($enc, $result, "Failed to encode_varint_float({$i})"); } }
function encode_tests() { run("encode_varint_int", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint_int(mt_rand()); } }); run("encode_varint_slide", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint_slide(mt_rand()); } }); run("encode_varint_float", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint_float(mt_rand()); } }); run("encode_varint_bc", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint_float(mt_rand()); } }); run("encode_varint_gmp", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint_float(mt_rand()); } }); run("encode_varint", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint(mt_rand()); } }); run("encode_neg_varint", function () { for ($i = 0; $i < LOOPS; $i++) { Protobuf::encode_varint(-mt_rand()); } }); }
function testEncodeVarintFloat() { foreach ($this->tests as $i => $enc) { if (!hasExactRepresentation($i) || $i < 0) { // Skip encoding floats without exact representation, as we will never get it right continue; } if (is_string($i)) { $i = (double) $i; } $result = Protobuf::encode_varint_float($i); $this->assertBinaryEqual($enc, $result, "Failed to encode_varint_float({$i})"); } }