avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1646473 - in /avro/trunk: CHANGES.txt lang/php/test/FloatIntEncodingTest.php
Date Thu, 18 Dec 2014 15:09:23 GMT
Author: tomwhite
Date: Thu Dec 18 15:09:22 2014
New Revision: 1646473

URL: http://svn.apache.org/r1646473
Log:
AVRO-1621. PHP: FloatIntEncodingTest fails for NAN.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/php/test/FloatIntEncodingTest.php

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1646473&r1=1646472&r2=1646473&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Dec 18 15:09:22 2014
@@ -105,6 +105,8 @@ Trunk (not yet released)
     AVRO-1623. Java: Fix GenericData#validate to correctly resolve unions.
     (Jeffrey Mullins via cutting)
 
+    AVRO-1621. PHP: FloatIntEncodingTest fails for NAN. (tomwhite)
+
 Avro 1.7.7 (23 July 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/php/test/FloatIntEncodingTest.php
URL: http://svn.apache.org/viewvc/avro/trunk/lang/php/test/FloatIntEncodingTest.php?rev=1646473&r1=1646472&r2=1646473&view=diff
==============================================================================
--- avro/trunk/lang/php/test/FloatIntEncodingTest.php (original)
+++ avro/trunk/lang/php/test/FloatIntEncodingTest.php Thu Dec 18 15:09:22 2014
@@ -94,10 +94,8 @@ class FloatIntEncodingTest extends PHPUn
   function special_vals_provider()
   {
     self::make_special_vals();
-    return array(array(self::DOUBLE_TYPE, self::$DOUBLE_NAN, self::$LONG_BITS_NAN),
-                 array(self::DOUBLE_TYPE, self::$DOUBLE_POS_INF, self::$LONG_BITS_POS_INF),
+    return array(array(self::DOUBLE_TYPE, self::$DOUBLE_POS_INF, self::$LONG_BITS_POS_INF),
                  array(self::DOUBLE_TYPE, self::$DOUBLE_NEG_INF, self::$LONG_BITS_NEG_INF),
-                 array(self::FLOAT_TYPE, self::$FLOAT_NAN, self::$INT_BITS_NAN),
                  array(self::FLOAT_TYPE, self::$FLOAT_POS_INF, self::$INT_BITS_POS_INF),
                  array(self::FLOAT_TYPE, self::$FLOAT_NEG_INF, self::$INT_BITS_NEG_INF));
   }
@@ -110,6 +108,21 @@ class FloatIntEncodingTest extends PHPUn
     $this->assert_encode_values($type, $val, $bits);
   }
 
+  function nan_vals_provider()
+  {
+    self::make_special_vals();
+    return array(array(self::DOUBLE_TYPE, self::$DOUBLE_NAN, self::$LONG_BITS_NAN),
+                 array(self::FLOAT_TYPE, self::$FLOAT_NAN, self::$INT_BITS_NAN));
+  }
+
+  /**
+   * @dataProvider nan_vals_provider
+   */
+  function test_encoding_nan_values($type, $val, $bits)
+  {
+    $this->assert_encode_nan_values($type, $val, $bits);
+  }
+
   function normal_vals_provider()
   {
     $ruby_to_generate_vals =<<<_RUBY
@@ -242,4 +255,35 @@ _RUBY;
                                 'ROUND TRIP BITS', $val, $round_trip_value));
   }
 
+  function assert_encode_nan_values($type, $val, $bits)
+  {
+    if (self::FLOAT_TYPE == $type)
+    {
+      $decoder = array('AvroIOBinaryDecoder', 'int_bits_to_float');
+      $encoder = array('AvroIOBinaryEncoder', 'float_to_int_bits');
+    }
+    else
+    {
+      $decoder = array('AvroIOBinaryDecoder', 'long_bits_to_double');
+      $encoder = array('AvroIOBinaryEncoder', 'double_to_long_bits');
+    }
+
+    $decoded_bits_val = call_user_func($decoder, $bits);
+    $this->assertTrue(is_nan($decoded_bits_val),
+                      sprintf("%s\n expected: '%f'\n    given: '%f'",
+                              'DECODED BITS', $val, $decoded_bits_val));
+
+    $encoded_val_bits = call_user_func($encoder, $val);
+    $this->assertEquals($bits, $encoded_val_bits,
+                        sprintf("%s\n expected: '%s'\n    given: '%s'",
+                                'ENCODED VAL',
+                                AvroDebug::hex_string($bits),
+                                AvroDebug::hex_string($encoded_val_bits)));
+
+    $round_trip_value = call_user_func($decoder, $encoded_val_bits);
+    $this->assertTrue(is_nan($round_trip_value),
+                      sprintf("%s\n expected: '%f'\n     given: '%f'",
+                              'ROUND TRIP BITS', $val, $round_trip_value));
+  }
+
 }



Mime
View raw message