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

See issue #220 on GitHub for reference.
This commit is contained in:
Daniele Alessandri
2014-11-07 14:19:08 +01:00
parent 54d467e530
commit 381ca99696
2 changed files with 10 additions and 4 deletions
@@ -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'));
}
@@ -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));
}
/**