This repository has been archived by the owner on Apr 26, 2019. It is now read-only.
/
red_set_spec.rb
133 lines (98 loc) · 2.86 KB
/
red_set_spec.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require 'spec_integration_helper'
describe RedSet do
describe "#initialize" do
it "creates a new RedSet instance and stores the key" do
set = RedSet.new("somekey")
set.key.should == "somekey"
end
end
describe "#add" do
it "adds the given value to the set" do
set = RedSet.new("somekey")
set.add(1)
set.value.should == [1]
end
end
describe "#value" do
it "returns the RedSet collection" do
set = RedSet.new("somekey")
set.value.should == []
set.add(1)
set.value.should == [1]
end
end
describe "#remove" do
it "removes the item from the set" do
set = RedSet.new("somekey")
set.add(1)
set.add(2)
set.value.should == [2, 1]
set.remove(2)
set.value.should == [1]
end
end
describe ".add" do
it "should add a member to the set" do
RedSet.add("somekey", 2)
set = RedSet.get("somekey")
set.should == [2]
end
it "should not add duplicates to the set" do
RedSet.add("somekey", 2)
RedSet.add("somekey", 2)
set = RedSet.get("somekey")
set.should == [2]
end
it "should not change the order of the set on attempted duplicate" do
RedSet.add("somekey", 2)
RedSet.add("somekey", 3)
RedSet.add("somekey", 2)
set = RedSet.get("somekey")
set.should == [3,2]
end
it "sets the score when one is provided" do
RedSet.add("somekey", 1, :score => lambda { 1000 })
RedSet.score("somekey", 1).should == "1000"
end
end
describe ".remove" do
it "should remove a member from the set" do
RedSet.add("somekey", 1)
RedSet.add("somekey", 2)
RedSet.remove("somekey", 2)
RedSet.get("somekey").should == [1]
end
end
describe ".score" do
it "returns the score of member within key" do
RedSet.add("somekey", 1)
RedSet.score("somekey", 1).should == "0"
end
end
describe ".get" do
it "should return the elements in reverse-inserted order" do
RedSet.add('somekey', 1)
RedSet.add('somekey', 2)
RedSet.add('somekey', 3)
RedSet.get('somekey').should == [3, 2, 1]
end
it "should pair the elements with their scores if :with_scores is true" do
RedSet.add('somekey', 1)
RedSet.add('somekey', 2)
RedSet.add('somekey', 3)
RedSet.get('somekey', :with_scores => true).should == [[3, 2], [2, 1], [1, 0]]
end
it "should return results bounded by provided pagination options" do
RedSet.add("somekey", 1)
RedSet.add("somekey", 2)
RedSet.get("somekey", :lower => 0, :upper => 0).should == [2]
RedSet.get("somekey", :lower => 1, :upper => 1).should == [1]
end
end
describe ".count" do
it "should return the total count" do
7.times {|i| RedSet.add("somekey",i)}
RedSet.count("somekey").should == 7
end
end
end