Parcourir la source

[tests] Use round() to avoid issues with floats on certain plaforms.

See issue #220 on GitHub for reference.
Daniele Alessandri il y a 10 ans
Parent
commit
5f3723bbd1

+ 6 - 2
tests/Predis/Command/HashIncrementByFloatTest.php

@@ -63,8 +63,10 @@ class HashIncrementByFloatTest extends PredisCommandTestCase
         $redis = $this->getClient();
 
         $this->assertSame('10.5', $redis->hincrbyfloat('metavars', 'foo', 10.5));
-        $this->assertSame('10.001', $redis->hincrbyfloat('metavars', 'hoge', 10.001));
+
+        $redis->hincrbyfloat('metavars', 'hoge', 10.001);
         $this->assertSame('11', $redis->hincrbyfloat('metavars', 'hoge', 0.999));
+
         $this->assertSame(array('foo' => '10.5', 'hoge' => '11'), $redis->hgetall('metavars'));
     }
 
@@ -76,8 +78,10 @@ class HashIncrementByFloatTest extends PredisCommandTestCase
         $redis = $this->getClient();
 
         $this->assertSame('-10.5', $redis->hincrbyfloat('metavars', 'foo', -10.5));
-        $this->assertSame('-10.001', $redis->hincrbyfloat('metavars', 'hoge', -10.001));
+
+        $redis->hincrbyfloat('metavars', 'hoge', -10.001);
         $this->assertSame('-11', $redis->hincrbyfloat('metavars', 'hoge', -0.999));
+
         $this->assertSame(array('foo' => '-10.5', 'hoge' => '-11'), $redis->hgetall('metavars'));
     }
 

+ 4 - 2
tests/Predis/Command/StringIncrementByFloatTest.php

@@ -75,9 +75,11 @@ class StringIncrementByFloatTest extends PredisCommandTestCase
 
         $redis->set('foo', 2);
 
+        // We use round() to avoid errors on some platforms, see the following
+        // issue https://github.com/nrk/predis/issues/220 for reference.
         $this->assertEquals(22.123, $redis->incrbyfloat('foo', 20.123));
-        $this->assertEquals(10, $redis->incrbyfloat('foo', -12.123));
-        $this->assertEquals(-100.01, $redis->incrbyfloat('foo', -110.01));
+        $this->assertEquals(10, round($redis->incrbyfloat('foo', -12.123), 5));
+        $this->assertEquals(-100.01, round($redis->incrbyfloat('foo', -110.01), 5));
     }
 
     /**