-
Notifications
You must be signed in to change notification settings - Fork 1
/
stal_test.lua
45 lines (34 loc) · 1.16 KB
/
stal_test.lua
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
local function assert_equal(expected, command)
local f = io.popen(command)
assert(f:read('*a') == expected)
end
local function redis(command)
assert(os.execute("redis-cli " .. command .. " > /dev/null"))
end
local function solve(str)
return "redis-cli --eval stal.lua , '" .. str .. "'"
end
-- Operations with sets
redis("FLUSHDB")
redis("SADD A 1 2 3")
redis("SADD B 2 3 4")
redis("SADD C 3 4 5")
assert_equal("2\n3\n", solve('["SINTER", "A", "B"]'))
assert_equal("1\n5\n", solve('["SDIFF", ["SUNION", "A", "C"], "B"]'))
-- Verify there's no keyspace pollution
assert_equal("3\n", solve('["DBSIZE"]'))
-- Operations with sorted sets
redis("FLUSHDB")
redis("ZADD A 1 a 2 b 3 c")
redis("ZADD B 1 b 2 c 3 d")
redis("ZADD C 1 d 2 e 3 f")
assert_equal("b\nc\n", solve('["ZRANGE", ["ZINTER", "2", "A", "B"], "0", "-1"]'))
-- Verify there's no keyspace pollution
assert_equal("3\n", solve('["DBSIZE"]'))
-- Operations with sorted and unsorted sets
redis("FLUSHDB")
redis("ZADD A 1 a 2 b 3 c")
redis("SADD B b c d")
assert_equal("b\nc\n", solve('["ZRANGE", ["ZINTER", "2", "A", "B"], "0", "-1"]'))
-- Verify there's no keyspace pollution
assert_equal("2\n", solve('["DBSIZE"]'))