Skip to content

Commit

Permalink
Not all supported Rubies have Float::INFINITY
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Aug 13, 2012
1 parent c99bb01 commit 8515097
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/redis.rb
Expand Up @@ -2207,7 +2207,7 @@ def _hashify

def _floatify(str)
if (inf = str.match(/^(-)?inf/i))
(inf[1] ? -1 : 1) * Float::INFINITY
(inf[1] ? -1.0 : 1.0) / 0.0
else
Float str
end
Expand Down
34 changes: 18 additions & 16 deletions test/lint/sorted_sets.rb
Expand Up @@ -2,6 +2,8 @@ module Lint

module SortedSets

Infinity = 1.0/0.0

def test_zadd
assert_equal 0, r.zcard("foo")
assert_equal true, r.zadd("foo", 1, "s1")
Expand Down Expand Up @@ -63,10 +65,10 @@ def test_zincrby
assert_equal 11.0, rv

rv = r.zincrby "bar", "-inf", "s1"
assert_equal(-Float::INFINITY, rv)
assert_equal(-Infinity, rv)

rv = r.zincrby "bar", "+inf", "s2"
assert_equal(+Float::INFINITY, rv)
assert_equal(+Infinity, rv)
end

def test_zrank
Expand Down Expand Up @@ -96,8 +98,8 @@ def test_zrange

r.zadd "bar", "-inf", "s1"
r.zadd "bar", "+inf", "s2"
assert_equal [["s1", -Float::INFINITY], ["s2", +Float::INFINITY]], r.zrange("bar", 0, 1, :with_scores => true)
assert_equal [["s1", -Float::INFINITY], ["s2", +Float::INFINITY]], r.zrange("bar", 0, 1, :withscores => true)
assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :with_scores => true)
assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :withscores => true)
end

def test_zrevrange
Expand All @@ -111,8 +113,8 @@ def test_zrevrange

r.zadd "bar", "-inf", "s1"
r.zadd "bar", "+inf", "s2"
assert_equal [["s2", +Float::INFINITY], ["s1", -Float::INFINITY]], r.zrevrange("bar", 0, 1, :with_scores => true)
assert_equal [["s2", +Float::INFINITY], ["s1", -Float::INFINITY]], r.zrevrange("bar", 0, 1, :withscores => true)
assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :with_scores => true)
assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :withscores => true)
end

def test_zrangebyscore
Expand Down Expand Up @@ -166,10 +168,10 @@ def test_zrangebyscore_with_withscores

r.zadd "bar", "-inf", "s1"
r.zadd "bar", "+inf", "s2"
assert_equal [["s1", -Float::INFINITY]], r.zrangebyscore("bar", -Float::INFINITY, +Float::INFINITY, :limit => [0, 1], :with_scores => true)
assert_equal [["s2", +Float::INFINITY]], r.zrangebyscore("bar", -Float::INFINITY, +Float::INFINITY, :limit => [1, 1], :with_scores => true)
assert_equal [["s1", -Float::INFINITY]], r.zrangebyscore("bar", -Float::INFINITY, +Float::INFINITY, :limit => [0, 1], :withscores => true)
assert_equal [["s2", +Float::INFINITY]], r.zrangebyscore("bar", -Float::INFINITY, +Float::INFINITY, :limit => [1, 1], :withscores => true)
assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :with_scores => true)
assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :with_scores => true)
assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :withscores => true)
assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :withscores => true)
end

def test_zrevrangebyscore_with_withscores
Expand All @@ -185,10 +187,10 @@ def test_zrevrangebyscore_with_withscores

r.zadd "bar", "-inf", "s1"
r.zadd "bar", "+inf", "s2"
assert_equal [["s2", +Float::INFINITY]], r.zrevrangebyscore("bar", +Float::INFINITY, -Float::INFINITY, :limit => [0, 1], :with_scores => true)
assert_equal [["s1", -Float::INFINITY]], r.zrevrangebyscore("bar", +Float::INFINITY, -Float::INFINITY, :limit => [1, 1], :with_scores => true)
assert_equal [["s2", +Float::INFINITY]], r.zrevrangebyscore("bar", +Float::INFINITY, -Float::INFINITY, :limit => [0, 1], :withscores => true)
assert_equal [["s1", -Float::INFINITY]], r.zrevrangebyscore("bar", +Float::INFINITY, -Float::INFINITY, :limit => [1, 1], :withscores => true)
assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :with_scores => true)
assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :with_scores => true)
assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :withscores => true)
assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :withscores => true)
end

def test_zcard
Expand All @@ -209,8 +211,8 @@ def test_zscore

r.zadd "bar", "-inf", "s1"
r.zadd "bar", "+inf", "s2"
assert_equal(-Float::INFINITY, r.zscore("bar", "s1"))
assert_equal(+Float::INFINITY, r.zscore("bar", "s2"))
assert_equal(-Infinity, r.zscore("bar", "s1"))
assert_equal(+Infinity, r.zscore("bar", "s2"))
end

def test_zremrangebyrank
Expand Down

0 comments on commit 8515097

Please sign in to comment.