Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
2812b945
R
redis
项目概览
hanoi2005
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2812b945
编写于
9月 21, 2012
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test for SRANDMEMBER with <count>.
上级
31fe053a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
112 addition
and
0 deletion
+112
-0
tests/unit/type/set.tcl
tests/unit/type/set.tcl
+112
-0
未找到文件。
tests/unit/type/set.tcl
浏览文件 @
2812b945
...
...
@@ -271,6 +271,118 @@ start_server {
}
}
test
"SRANDMEMBER with <count> against non existing key"
{
r srandmember nonexisting_key 100
}
{}
foreach
{
type contents
}
{
hashtable
{
1 5 10 50 125 50000 33959417 4775547 65434162
12098459 427716 483706 2726473884 72615637475
MARY PATRICIA LINDA BARBARA ELIZABETH JENNIFER MARIA
SUSAN MARGARET DOROTHY LISA NANCY KAREN BETTY HELEN
SANDRA DONNA CAROL RUTH SHARON MICHELLE LAURA SARAH
KIMBERLY DEBORAH JESSICA SHIRLEY CYNTHIA ANGELA MELISSA
BRENDA AMY ANNA REBECCA VIRGINIA KATHLEEN
}
intset
{
0 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
}
}
{
test
"SRANDMEMBER with <count> -
$type
"
{
create_set myset $contents
unset -nocomplain myset
array set myset
{}
foreach ele
[
r smembers myset
]
{
set myset
(
$ele
)
1
}
assert_equal
[
lsort $contents
]
[
lsort
[
array names myset
]]
# Make sure that a count of 0 is handled correctly.
assert_equal
[
r srandmember myset 0
]
{}
# We'll stress different parts of the code, see the implementation
# of SRANDMEMBER for more information, but basically there are
# four different code paths.
#
# PATH 1: Use negative count.
#
# 1) Check that it returns repeated elements.
set res
[
r srandmember myset -100
]
assert_equal
[
llength $res
]
100
# 2) Check that all the elements actually belong to the
# original set.
foreach ele $res
{
assert
{[
info exists myset
(
$ele
)]}
}
# 3) Check that eventually all the elements are returned.
unset -nocomplain auxset
set iterations 1000
while
{
$iterations
!= 0
}
{
incr iterations -1
set res
[
r srandmember myset -10
]
foreach ele $res
{
set auxset
(
$ele
)
1
}
if
{[
lsort
[
array names myset
]]
eq
[
lsort
[
array names auxset
]]}
{
break
;
}
}
assert
{
$iterations
!= 0
}
# PATH 2: positive count
(
unique behavior
)
with requested size
# equal or greater than set size.
foreach size
{
50 100
}
{
set res
[
r srandmember myset $size
]
assert_equal
[
llength $res
]
50
assert_equal
[
lsort $res
]
[
lsort
[
array names myset
]]
}
# PATH 3: Ask almost as elements as there are in the set.
# In this case the implementation will duplicate the original
# set and will remove random elements up to the requested size.
#
# PATH 4: Ask a number of elements definitely smaller than
# the set size.
#
# We can test both the code paths just changing the size but
# using the same code.
foreach size
{
45 5
}
{
set res
[
r srandmember myset $size
]
assert_equal
[
llength $res
]
$size
# 1) Check that all the elements actually belong to the
# original set.
foreach ele $res
{
assert
{[
info exists myset
(
$ele
)]}
}
# 2) Check that eventually all the elements are returned.
unset -nocomplain auxset
set iterations 1000
while
{
$iterations
!= 0
}
{
incr iterations -1
set res
[
r srandmember myset -10
]
foreach ele $res
{
set auxset
(
$ele
)
1
}
if
{[
lsort
[
array names myset
]]
eq
[
lsort
[
array names auxset
]]}
{
break
;
}
}
assert
{
$iterations
!= 0
}
}
}
}
proc setup_move
{}
{
r del myset3 myset4
create_set myset1
{
1 a b
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录