Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
42e3630d
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,发现更多精彩内容 >>
提交
42e3630d
编写于
2月 27, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Basic BITPOS tests.
上级
1892b562
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
102 addition
and
0 deletion
+102
-0
tests/unit/bitops.tcl
tests/unit/bitops.tcl
+102
-0
未找到文件。
tests/unit/bitops.tcl
浏览文件 @
42e3630d
...
...
@@ -203,4 +203,106 @@ start_server {tags {"bitops"}} {
r set a
"
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
"
r bitop or x a b
}
{
32
}
test
{
BITPOS bit=0 with empty key returns 0
}
{
r del str
r bitpos str 0
}
{
0
}
test
{
BITPOS bit=1 with empty key returns -1
}
{
r del str
r bitpos str 1
}
{
-1
}
test
{
BITPOS bit=0 with string less than 1 word works
}
{
r set str
"
\xff\xf0\x00
"
r bitpos str 0
}
{
12
}
test
{
BITPOS bit=1 with string less than 1 word works
}
{
r set str
"
\x00\x0f\x00
"
r bitpos str 1
}
{
12
}
test
{
BITPOS bit=0 starting at unaligned address
}
{
r set str
"
\xff\xf0\x00
"
r bitpos str 0 1
}
{
12
}
test
{
BITPOS bit=1 starting at unaligned address
}
{
r set str
"
\x00\x0f\xff
"
r bitpos str 1 1
}
{
12
}
test
{
BITPOS bit=0 unaligned+full word+reminder
}
{
r del str
r set str
"
\xff\xff\xff
"
;
# Prefix
# Followed by two
(
or four in 32 bit systems
)
full words
r append str
"
\xff\xff\xff\xff\xff\xff\xff\xff
"
r append str
"
\xff\xff\xff\xff\xff\xff\xff\xff
"
r append str
"
\xff\xff\xff\xff\xff\xff\xff\xff
"
# First zero bit.
r append str
"
\x0f
"
assert
{[
r bitpos str 0
]
== 216
}
assert
{[
r bitpos str 0 1
]
== 216
}
assert
{[
r bitpos str 0 2
]
== 216
}
assert
{[
r bitpos str 0 3
]
== 216
}
assert
{[
r bitpos str 0 4
]
== 216
}
assert
{[
r bitpos str 0 5
]
== 216
}
assert
{[
r bitpos str 0 6
]
== 216
}
assert
{[
r bitpos str 0 7
]
== 216
}
assert
{[
r bitpos str 0 8
]
== 216
}
}
test
{
BITPOS bit=1 unaligned+full word+reminder
}
{
r del str
r set str
"
\x00\x00\x00
"
;
# Prefix
# Followed by two
(
or four in 32 bit systems
)
full words
r append str
"
\x00\x00\x00\x00\x00\x00\x00\x00
"
r append str
"
\x00\x00\x00\x00\x00\x00\x00\x00
"
r append str
"
\x00\x00\x00\x00\x00\x00\x00\x00
"
# First zero bit.
r append str
"
\xf0
"
assert
{[
r bitpos str 1
]
== 216
}
assert
{[
r bitpos str 1 1
]
== 216
}
assert
{[
r bitpos str 1 2
]
== 216
}
assert
{[
r bitpos str 1 3
]
== 216
}
assert
{[
r bitpos str 1 4
]
== 216
}
assert
{[
r bitpos str 1 5
]
== 216
}
assert
{[
r bitpos str 1 6
]
== 216
}
assert
{[
r bitpos str 1 7
]
== 216
}
assert
{[
r bitpos str 1 8
]
== 216
}
}
test
{
BITPOS bit=1 returns -1 if string is all 0 bits
}
{
r set str
""
for
{
set j 0
}
{
$j
< 20
}
{
incr j
}
{
assert
{[
r bitpos str 1
]
== -1
}
r append str
"
\x00
"
}
}
test
{
BITPOS bit=0 works with intervals
}
{
r set str
"
\x00\xff\x00
"
assert
{[
r bitpos str 0 0 -1
]
== 0
}
assert
{[
r bitpos str 0 1 -1
]
== 16
}
assert
{[
r bitpos str 0 2 -1
]
== 16
}
assert
{[
r bitpos str 0 2 200
]
== 16
}
assert
{[
r bitpos str 0 1 1
]
== -1
}
}
test
{
BITPOS bit=1 works with intervals
}
{
r set str
"
\x00\xff\x00
"
assert
{[
r bitpos str 1 0 -1
]
== 8
}
assert
{[
r bitpos str 1 1 -1
]
== 8
}
assert
{[
r bitpos str 1 2 -1
]
== -1
}
assert
{[
r bitpos str 1 2 200
]
== -1
}
assert
{[
r bitpos str 1 1 1
]
== 8
}
}
test
{
BITPOS bit=0 changes behavior if end is given
}
{
r set str
"
\xff\xff\xff
"
assert
{[
r bitpos str 0
]
== 24
}
assert
{[
r bitpos str 0 0 -1
]
== -1
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录