PageRenderTime 75ms CodeModel.GetById 14ms app.highlight 58ms RepoModel.GetById 2ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/test/commands_on_sorted_sets_test.rb

https://github.com/delowong/logstash
Ruby | 109 lines | 84 code | 24 blank | 1 comment | 0 complexity | 73ce3b3777969709ce93d5f4af95d297 MD5 | raw file
  1# encoding: UTF-8
  2
  3require File.expand_path("helper", File.dirname(__FILE__))
  4require "lint/sorted_sets"
  5
  6class TestCommandsOnSortedSets < Test::Unit::TestCase
  7
  8  include Helper::Client
  9  include Lint::SortedSets
 10
 11  def test_zcount
 12    r.zadd "foo", 1, "s1"
 13    r.zadd "foo", 2, "s2"
 14    r.zadd "foo", 3, "s3"
 15
 16    assert_equal 2, r.zcount("foo", 2, 3)
 17  end
 18
 19  def test_zunionstore
 20    r.zadd "foo", 1, "s1"
 21    r.zadd "bar", 2, "s2"
 22    r.zadd "foo", 3, "s3"
 23    r.zadd "bar", 4, "s4"
 24
 25    assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
 26    assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
 27  end
 28
 29  def test_zunionstore_with_weights
 30    r.zadd "foo", 1, "s1"
 31    r.zadd "foo", 3, "s3"
 32    r.zadd "bar", 20, "s2"
 33    r.zadd "bar", 40, "s4"
 34
 35    assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
 36    assert_equal ["s1", "s3", "s2", "s4"], r.zrange("foobar", 0, -1)
 37
 38    assert_equal 4, r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1])
 39    assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
 40  end
 41
 42  def test_zunionstore_with_aggregate
 43    r.zadd "foo", 1, "s1"
 44    r.zadd "foo", 2, "s2"
 45    r.zadd "bar", 4, "s2"
 46    r.zadd "bar", 3, "s3"
 47
 48    assert_equal 3, r.zunionstore("foobar", ["foo", "bar"])
 49    assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
 50
 51    assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min)
 52    assert_equal ["s1", "s2", "s3"], r.zrange("foobar", 0, -1)
 53
 54    assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max)
 55    assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
 56  end
 57
 58  def test_zinterstore
 59    r.zadd "foo", 1, "s1"
 60    r.zadd "bar", 2, "s1"
 61    r.zadd "foo", 3, "s3"
 62    r.zadd "bar", 4, "s4"
 63
 64    assert_equal 1, r.zinterstore("foobar", ["foo", "bar"])
 65    assert_equal ["s1"], r.zrange("foobar", 0, -1)
 66  end
 67
 68  def test_zinterstore_with_weights
 69    r.zadd "foo", 1, "s1"
 70    r.zadd "foo", 2, "s2"
 71    r.zadd "foo", 3, "s3"
 72    r.zadd "bar", 20, "s2"
 73    r.zadd "bar", 30, "s3"
 74    r.zadd "bar", 40, "s4"
 75
 76    assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
 77    assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
 78
 79    assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1])
 80    assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
 81
 82    assert_equal 40.0, r.zscore("foobar", "s2")
 83    assert_equal 60.0, r.zscore("foobar", "s3")
 84  end
 85
 86  def test_zinterstore_with_aggregate
 87    r.zadd "foo", 1, "s1"
 88    r.zadd "foo", 2, "s2"
 89    r.zadd "foo", 3, "s3"
 90    r.zadd "bar", 20, "s2"
 91    r.zadd "bar", 30, "s3"
 92    r.zadd "bar", 40, "s4"
 93
 94    assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
 95    assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
 96    assert_equal 22.0, r.zscore("foobar", "s2")
 97    assert_equal 33.0, r.zscore("foobar", "s3")
 98
 99    assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min)
100    assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
101    assert_equal 2.0, r.zscore("foobar", "s2")
102    assert_equal 3.0, r.zscore("foobar", "s3")
103
104    assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max)
105    assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
106    assert_equal 20.0, r.zscore("foobar", "s2")
107    assert_equal 30.0, r.zscore("foobar", "s3")
108  end
109end