Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cd91722a
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cd91722a
编写于
6月 09, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more unit tests
上级
c06c6789
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
25 addition
and
12 deletion
+25
-12
paddle/strings/stringpiece.cc
paddle/strings/stringpiece.cc
+2
-2
paddle/strings/stringpiece.h
paddle/strings/stringpiece.h
+1
-7
paddle/strings/stringpiece_test.cc
paddle/strings/stringpiece_test.cc
+22
-3
未找到文件。
paddle/strings/stringpiece.cc
浏览文件 @
cd91722a
...
@@ -30,8 +30,8 @@ StringPiece::StringPiece(const char* d, size_t n) : data_(d), size_(n) {
...
@@ -30,8 +30,8 @@ StringPiece::StringPiece(const char* d, size_t n) : data_(d), size_(n) {
"StringPiece requires len to be 0 for NULL data"
);
"StringPiece requires len to be 0 for NULL data"
);
}
}
StringPiece
::
StringPiece
(
const
char
*
s
)
:
data_
(
s
)
,
size_
(
strlen
(
s
))
{
StringPiece
::
StringPiece
(
const
char
*
s
)
:
data_
(
s
)
{
if
(
s
==
NULL
)
size_
=
0
;
size_
=
(
s
==
NULL
)
?
0
:
strlen
(
s
)
;
}
}
StringPiece
::
StringPiece
(
const
std
::
string
&
s
)
StringPiece
::
StringPiece
(
const
std
::
string
&
s
)
...
...
paddle/strings/stringpiece.h
浏览文件 @
cd91722a
...
@@ -40,14 +40,8 @@ public:
...
@@ -40,14 +40,8 @@ public:
StringPiece
(
const
char
*
s
);
StringPiece
(
const
char
*
s
);
StringPiece
(
const
std
::
string
&
s
);
StringPiece
(
const
std
::
string
&
s
);
// For a string, cap() returns the size of storage and len()
// returns the currently used storage. For a StringPiece these
// are the same value.
size_t
cap
()
const
{
return
size_
;
}
size_t
len
()
const
{
return
size_
;
}
size_t
size
()
const
{
return
size_
;
}
const
char
*
data
()
const
{
return
data_
;
}
const
char
*
data
()
const
{
return
data_
;
}
size_t
len
()
const
{
return
size_
;
}
char
operator
[](
size_t
n
)
const
{
char
operator
[](
size_t
n
)
const
{
assert
(
n
<
len
());
assert
(
n
<
len
());
...
...
paddle/strings/stringpiece_test.cc
浏览文件 @
cd91722a
...
@@ -22,7 +22,6 @@ TEST(StringPiece, Construct) {
...
@@ -22,7 +22,6 @@ TEST(StringPiece, Construct) {
paddle
::
StringPiece
s
;
paddle
::
StringPiece
s
;
EXPECT_EQ
(
NULL
,
s
.
data
());
EXPECT_EQ
(
NULL
,
s
.
data
());
EXPECT_EQ
(
0U
,
s
.
len
());
EXPECT_EQ
(
0U
,
s
.
len
());
EXPECT_EQ
(
0U
,
s
.
cap
());
}
}
{
{
EXPECT_THROW
([]
{
paddle
::
StringPiece
s
(
NULL
,
10000U
);
}(),
EXPECT_THROW
([]
{
paddle
::
StringPiece
s
(
NULL
,
10000U
);
}(),
...
@@ -43,12 +42,10 @@ TEST(StringPiece, Construct) {
...
@@ -43,12 +42,10 @@ TEST(StringPiece, Construct) {
TEST
(
StringPiece
,
CopyAndAssign
)
{
TEST
(
StringPiece
,
CopyAndAssign
)
{
paddle
::
StringPiece
empty
;
paddle
::
StringPiece
empty
;
EXPECT_EQ
(
0U
,
empty
.
len
());
EXPECT_EQ
(
0U
,
empty
.
len
());
EXPECT_EQ
(
0U
,
empty
.
cap
());
paddle
::
StringPiece
a
(
"hello"
);
paddle
::
StringPiece
a
(
"hello"
);
paddle
::
StringPiece
b
=
a
;
paddle
::
StringPiece
b
=
a
;
EXPECT_EQ
(
b
.
len
(),
strlen
(
"hello"
));
EXPECT_EQ
(
b
.
len
(),
strlen
(
"hello"
));
EXPECT_EQ
(
b
.
cap
(),
strlen
(
"hello"
));
EXPECT_EQ
(
a
,
b
);
EXPECT_EQ
(
a
,
b
);
std
::
string
storage
(
"hello"
);
std
::
string
storage
(
"hello"
);
...
@@ -56,3 +53,25 @@ TEST(StringPiece, CopyAndAssign) {
...
@@ -56,3 +53,25 @@ TEST(StringPiece, CopyAndAssign) {
EXPECT_EQ
(
a
,
c
);
EXPECT_EQ
(
a
,
c
);
EXPECT_NE
(
a
.
data
(),
c
.
data
());
EXPECT_NE
(
a
.
data
(),
c
.
data
());
}
}
TEST
(
StringPiece
,
Comparison
)
{
{
paddle
::
StringPiece
a
(
"hello"
);
paddle
::
StringPiece
b
(
"world"
);
EXPECT_TRUE
(
a
!=
b
);
EXPECT_FALSE
(
a
==
b
);
EXPECT_TRUE
(
a
<
b
);
EXPECT_TRUE
(
a
<=
b
);
EXPECT_FALSE
(
a
>
b
);
EXPECT_FALSE
(
a
>=
b
);
}
{
paddle
::
StringPiece
a
,
b
;
EXPECT_TRUE
(
a
==
b
);
EXPECT_FALSE
(
a
!=
b
);
EXPECT_FALSE
(
a
<
b
);
EXPECT_FALSE
(
a
>
b
);
EXPECT_TRUE
(
a
<=
b
);
EXPECT_TRUE
(
a
>=
b
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录