forked from redis/redis-rb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Port all contest tests to cutest.
- Loading branch information
Showing
45 changed files
with
2,562 additions
and
3,184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: UTF-8 | ||
|
||
require File.expand_path("./helper", File.dirname(__FILE__)) | ||
|
||
setup do | ||
init Redis.new(OPTIONS) | ||
end | ||
|
||
load './test/lint/hashes.rb' | ||
|
||
test "HSETNX" do |r| | ||
r.hset("foo", "f1", "s1") | ||
r.hsetnx("foo", "f1", "s2") | ||
|
||
assert "s1" == r.hget("foo", "f1") | ||
|
||
r.del("foo") | ||
r.hsetnx("foo", "f1", "s2") | ||
|
||
assert "s2" == r.hget("foo", "f1") | ||
end | ||
|
||
test "HMGET" do |r| | ||
r.hset("foo", "f1", "s1") | ||
r.hset("foo", "f2", "s2") | ||
r.hset("foo", "f3", "s3") | ||
|
||
assert ["s2", "s3"] == r.hmget("foo", "f2", "f3") | ||
end | ||
|
||
test "HMGET mapped" do |r| | ||
r.hset("foo", "f1", "s1") | ||
r.hset("foo", "f2", "s2") | ||
r.hset("foo", "f3", "s3") | ||
|
||
assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1")) | ||
assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2")) | ||
end | ||
|
||
test "Mapped HMSET" do |r| | ||
r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2") | ||
|
||
assert "s1" == r.hget("foo", "f1") | ||
assert "s2" == r.hget("foo", "f2") | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# encoding: UTF-8 | ||
|
||
require File.expand_path("./helper", File.dirname(__FILE__)) | ||
|
||
setup do | ||
init Redis.new(OPTIONS) | ||
end | ||
|
||
load './test/lint/lists.rb' | ||
|
||
test "RPUSHX" do |r| | ||
r.rpushx "foo", "s1" | ||
r.rpush "foo", "s2" | ||
r.rpushx "foo", "s3" | ||
|
||
assert 2 == r.llen("foo") | ||
assert ["s2", "s3"] == r.lrange("foo", 0, -1) | ||
end | ||
|
||
test "LPUSHX" do |r| | ||
r.lpushx "foo", "s1" | ||
r.lpush "foo", "s2" | ||
r.lpushx "foo", "s3" | ||
|
||
assert 2 == r.llen("foo") | ||
assert ["s3", "s2"] == r.lrange("foo", 0, -1) | ||
end | ||
|
||
test "LINSERT" do |r| | ||
r.rpush "foo", "s1" | ||
r.rpush "foo", "s3" | ||
r.linsert "foo", :before, "s3", "s2" | ||
|
||
assert ["s1", "s2", "s3"] == r.lrange("foo", 0, -1) | ||
|
||
assert_raise(RuntimeError) do | ||
r.linsert "foo", :anywhere, "s3", "s2" | ||
end | ||
end | ||
|
||
test "RPOPLPUSH" do |r| | ||
r.rpush "foo", "s1" | ||
r.rpush "foo", "s2" | ||
|
||
assert "s2" == r.rpoplpush("foo", "bar") | ||
assert ["s2"] == r.lrange("bar", 0, -1) | ||
assert "s1" == r.rpoplpush("foo", "bar") | ||
assert ["s1", "s2"] == r.lrange("bar", 0, -1) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# encoding: UTF-8 | ||
|
||
require File.expand_path("./helper", File.dirname(__FILE__)) | ||
|
||
setup do | ||
init Redis.new(OPTIONS) | ||
end | ||
|
||
load './test/lint/sets.rb' | ||
|
||
test "SMOVE" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "bar", "s2" | ||
|
||
assert r.smove("foo", "bar", "s1") | ||
assert r.sismember("bar", "s1") | ||
end | ||
|
||
test "SINTER" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
|
||
assert ["s2"] == r.sinter("foo", "bar") | ||
end | ||
|
||
test "SINTERSTORE" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
|
||
r.sinterstore("baz", "foo", "bar") | ||
|
||
assert ["s2"] == r.smembers("baz") | ||
end | ||
|
||
test "SUNION" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
r.sadd "bar", "s3" | ||
|
||
assert ["s1", "s2", "s3"] == r.sunion("foo", "bar").sort | ||
end | ||
|
||
test "SUNIONSTORE" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
r.sadd "bar", "s3" | ||
|
||
r.sunionstore("baz", "foo", "bar") | ||
|
||
assert ["s1", "s2", "s3"] == r.smembers("baz").sort | ||
end | ||
|
||
test "SDIFF" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
r.sadd "bar", "s3" | ||
|
||
assert ["s1"] == r.sdiff("foo", "bar") | ||
assert ["s3"] == r.sdiff("bar", "foo") | ||
end | ||
|
||
test "SDIFFSTORE" do |r| | ||
r.sadd "foo", "s1" | ||
r.sadd "foo", "s2" | ||
r.sadd "bar", "s2" | ||
r.sadd "bar", "s3" | ||
|
||
r.sdiffstore("baz", "foo", "bar") | ||
|
||
assert ["s1"] == r.smembers("baz") | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# encoding: UTF-8 | ||
|
||
require File.expand_path("./helper", File.dirname(__FILE__)) | ||
|
||
setup do | ||
init Redis.new(OPTIONS) | ||
end | ||
|
||
load './test/lint/sorted_sets.rb' | ||
|
||
test "ZCOUNT" do |r| | ||
r.zadd "foo", 1, "s1" | ||
r.zadd "foo", 2, "s2" | ||
r.zadd "foo", 3, "s3" | ||
|
||
assert 2 == r.zcount("foo", 2, 3) | ||
end | ||
|
||
test "ZUNIONSTORE" do |r| | ||
r.zadd "foo", 1, "s1" | ||
r.zadd "bar", 2, "s2" | ||
r.zadd "foo", 3, "s3" | ||
r.zadd "bar", 4, "s4" | ||
|
||
assert 4 == r.zunionstore("foobar", ["foo", "bar"]) | ||
assert ["s1", "s2", "s3", "s4"] == r.zrange("foobar", 0, -1) | ||
end | ||
|
||
test "ZUNIONSTORE with WEIGHTS" do |r| | ||
r.zadd "foo", 1, "s1" | ||
r.zadd "foo", 3, "s3" | ||
r.zadd "bar", 20, "s2" | ||
r.zadd "bar", 40, "s4" | ||
|
||
assert 4 == r.zunionstore("foobar", ["foo", "bar"]) | ||
assert ["s1", "s3", "s2", "s4"] == r.zrange("foobar", 0, -1) | ||
|
||
assert 4 == r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1]) | ||
assert ["s1", "s2", "s3", "s4"] == r.zrange("foobar", 0, -1) | ||
end | ||
|
||
test "ZUNIONSTORE with AGGREGATE" do |r| | ||
r.zadd "foo", 1, "s1" | ||
r.zadd "foo", 2, "s2" | ||
r.zadd "bar", 4, "s2" | ||
r.zadd "bar", 3, "s3" | ||
|
||
assert 3 == r.zunionstore("foobar", ["foo", "bar"]) | ||
assert ["s1", "s3", "s2"] == r.zrange("foobar", 0, -1) | ||
|
||
assert 3 == r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min) | ||
assert ["s1", "s2", "s3"] == r.zrange("foobar", 0, -1) | ||
|
||
assert 3 == r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max) | ||
assert ["s1", "s3", "s2"] == r.zrange("foobar", 0, -1) | ||
end | ||
|
||
test "ZINTERSTORE" do |r| | ||
r.zadd "foo", 1, "s1" | ||
r.zadd "bar", 2, "s1" | ||
r.zadd "foo", 3, "s3" | ||
r.zadd "bar", 4, "s4" | ||
|
||
assert 1 == r.zinterstore("foobar", ["foo", "bar"]) | ||
assert ["s1"] == r.zrange("foobar", 0, -1) | ||
end | ||
|
||
test "ZINTERSTORE with WEIGHTS" do |r| | ||
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 2 == r.zinterstore("foobar", ["foo", "bar"]) | ||
assert ["s2", "s3"] == r.zrange("foobar", 0, -1) | ||
|
||
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1]) | ||
assert ["s2", "s3"] == r.zrange("foobar", 0, -1) | ||
|
||
assert "40" == r.zscore("foobar", "s2") | ||
assert "60" == r.zscore("foobar", "s3") | ||
end | ||
|
||
test "ZINTERSTORE with AGGREGATE" do |r| | ||
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 2 == r.zinterstore("foobar", ["foo", "bar"]) | ||
assert ["s2", "s3"] == r.zrange("foobar", 0, -1) | ||
assert "22" == r.zscore("foobar", "s2") | ||
assert "33" == r.zscore("foobar", "s3") | ||
|
||
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min) | ||
assert ["s2", "s3"] == r.zrange("foobar", 0, -1) | ||
assert "2" == r.zscore("foobar", "s2") | ||
assert "3" == r.zscore("foobar", "s3") | ||
|
||
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max) | ||
assert ["s2", "s3"] == r.zrange("foobar", 0, -1) | ||
assert "20" == r.zscore("foobar", "s2") | ||
assert "30" == r.zscore("foobar", "s3") | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# encoding: UTF-8 | ||
|
||
require File.expand_path("./helper", File.dirname(__FILE__)) | ||
|
||
setup do | ||
init Redis.new(OPTIONS) | ||
end | ||
|
||
load './test/lint/strings.rb' | ||
|
||
test "MGET" do |r| | ||
r.set("foo", "s1") | ||
r.set("bar", "s2") | ||
|
||
assert ["s1", "s2"] == r.mget("foo", "bar") | ||
assert ["s1", "s2", nil] == r.mget("foo", "bar", "baz") | ||
end | ||
|
||
test "MGET mapped" do |r| | ||
r.set("foo", "s1") | ||
r.set("bar", "s2") | ||
|
||
response = r.mapped_mget("foo", "bar") | ||
|
||
assert "s1" == response["foo"] | ||
assert "s2" == response["bar"] | ||
|
||
response = r.mapped_mget("foo", "bar", "baz") | ||
|
||
assert "s1" == response["foo"] | ||
assert "s2" == response["bar"] | ||
assert nil == response["baz"] | ||
end | ||
|
||
test "MSET" do |r| | ||
r.mset(:foo, "s1", :bar, "s2") | ||
|
||
assert "s1" == r.get("foo") | ||
assert "s2" == r.get("bar") | ||
end | ||
|
||
test "MSET mapped" do |r| | ||
r.mapped_mset(:foo => "s1", :bar => "s2") | ||
|
||
assert "s1" == r.get("foo") | ||
assert "s2" == r.get("bar") | ||
end | ||
|
||
test "MSETNX" do |r| | ||
r.set("foo", "s1") | ||
r.msetnx(:foo, "s2", :bar, "s3") | ||
|
||
assert "s1" == r.get("foo") | ||
assert nil == r.get("bar") | ||
end | ||
|
||
test "MSETNX mapped" do |r| | ||
r.set("foo", "s1") | ||
r.mapped_msetnx(:foo => "s2", :bar => "s3") | ||
|
||
assert "s1" == r.get("foo") | ||
assert nil == r.get("bar") | ||
end | ||
|
||
test "STRLEN" do |r| | ||
r.set "foo", "lorem" | ||
|
||
assert 5 == r.strlen("foo") | ||
end | ||
|
Oops, something went wrong.