/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. require File.expand_path("helper", File.dirname(__FILE__))
  3. require "lint/sorted_sets"
  4. class TestCommandsOnSortedSets < Test::Unit::TestCase
  5. include Helper::Client
  6. include Lint::SortedSets
  7. def test_zcount
  8. r.zadd "foo", 1, "s1"
  9. r.zadd "foo", 2, "s2"
  10. r.zadd "foo", 3, "s3"
  11. assert_equal 2, r.zcount("foo", 2, 3)
  12. end
  13. def test_zunionstore
  14. r.zadd "foo", 1, "s1"
  15. r.zadd "bar", 2, "s2"
  16. r.zadd "foo", 3, "s3"
  17. r.zadd "bar", 4, "s4"
  18. assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
  19. assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
  20. end
  21. def test_zunionstore_with_weights
  22. r.zadd "foo", 1, "s1"
  23. r.zadd "foo", 3, "s3"
  24. r.zadd "bar", 20, "s2"
  25. r.zadd "bar", 40, "s4"
  26. assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
  27. assert_equal ["s1", "s3", "s2", "s4"], r.zrange("foobar", 0, -1)
  28. assert_equal 4, r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1])
  29. assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
  30. end
  31. def test_zunionstore_with_aggregate
  32. r.zadd "foo", 1, "s1"
  33. r.zadd "foo", 2, "s2"
  34. r.zadd "bar", 4, "s2"
  35. r.zadd "bar", 3, "s3"
  36. assert_equal 3, r.zunionstore("foobar", ["foo", "bar"])
  37. assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
  38. assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min)
  39. assert_equal ["s1", "s2", "s3"], r.zrange("foobar", 0, -1)
  40. assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max)
  41. assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
  42. end
  43. def test_zinterstore
  44. r.zadd "foo", 1, "s1"
  45. r.zadd "bar", 2, "s1"
  46. r.zadd "foo", 3, "s3"
  47. r.zadd "bar", 4, "s4"
  48. assert_equal 1, r.zinterstore("foobar", ["foo", "bar"])
  49. assert_equal ["s1"], r.zrange("foobar", 0, -1)
  50. end
  51. def test_zinterstore_with_weights
  52. r.zadd "foo", 1, "s1"
  53. r.zadd "foo", 2, "s2"
  54. r.zadd "foo", 3, "s3"
  55. r.zadd "bar", 20, "s2"
  56. r.zadd "bar", 30, "s3"
  57. r.zadd "bar", 40, "s4"
  58. assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
  59. assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
  60. assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1])
  61. assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
  62. assert_equal 40.0, r.zscore("foobar", "s2")
  63. assert_equal 60.0, r.zscore("foobar", "s3")
  64. end
  65. def test_zinterstore_with_aggregate
  66. r.zadd "foo", 1, "s1"
  67. r.zadd "foo", 2, "s2"
  68. r.zadd "foo", 3, "s3"
  69. r.zadd "bar", 20, "s2"
  70. r.zadd "bar", 30, "s3"
  71. r.zadd "bar", 40, "s4"
  72. assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
  73. assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
  74. assert_equal 22.0, r.zscore("foobar", "s2")
  75. assert_equal 33.0, r.zscore("foobar", "s3")
  76. assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min)
  77. assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
  78. assert_equal 2.0, r.zscore("foobar", "s2")
  79. assert_equal 3.0, r.zscore("foobar", "s3")
  80. assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max)
  81. assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
  82. assert_equal 20.0, r.zscore("foobar", "s2")
  83. assert_equal 30.0, r.zscore("foobar", "s3")
  84. end
  85. end