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