Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
13abfa51
T
TinySTL
项目概览
OpenDocCN
/
TinySTL
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TinySTL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
13abfa51
编写于
1月 05, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成circular_buffer的单元测试
上级
b7362882
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
121 addition
and
0 deletion
+121
-0
TinySTL/Test/CircularBufferTest.cpp
TinySTL/Test/CircularBufferTest.cpp
+85
-0
TinySTL/Test/CircularBufferTest.h
TinySTL/Test/CircularBufferTest.h
+36
-0
未找到文件。
TinySTL/Test/CircularBufferTest.cpp
0 → 100644
浏览文件 @
13abfa51
#include "CircularBufferTest.h"
namespace
TinySTL
{
namespace
CircularBufferTest
{
void
testCase1
(){
tsCB
<
int
,
10
>
cb1
(
10
,
1
);
for
(
auto
i
=
0
;
i
!=
10
;
++
i
)
assert
(
cb1
[
i
]
==
1
);
int
arr
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
tsCB
<
int
,
10
>
cb2
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
for
(
auto
i
=
0
;
i
!=
10
;
++
i
)
assert
(
cb2
[
i
]
==
i
);
auto
cb3
(
cb2
);
assert
(
circular_buffer_equal
(
cb2
,
cb3
));
auto
cb4
(
std
::
move
(
cb2
));
//cb2 clear
assert
(
circular_buffer_equal
(
cb3
,
cb4
));
auto
cb5
=
cb3
;
assert
(
circular_buffer_equal
(
cb3
,
cb5
));
auto
cb6
=
std
::
move
(
cb3
);
//cb3 clear
assert
(
circular_buffer_equal
(
cb5
,
cb6
));
}
void
testCase2
(){
tsCB
<
int
,
2
>
cb
(
1
);
assert
(
cb
.
size
()
==
1
);
cb
.
pop_front
();
assert
(
!
cb
.
full
());
assert
(
cb
.
size
()
==
0
);
assert
(
cb
.
empty
());
cb
.
push_back
(
1
),
cb
.
push_back
(
2
);
assert
(
cb
.
full
());
assert
(
!
cb
.
empty
());
assert
(
cb
.
size
()
==
2
);
}
void
testCase3
(){
tsCB
<
std
::
string
,
3
>
cb
(
3
);
cb
[
0
]
=
"one"
,
cb
[
1
]
=
"two"
,
cb
[
2
]
=
"three"
;
assert
(
*
(
cb
.
first
())
==
"one"
&&
*
(
cb
.
last
())
==
"three"
);
assert
(
cb
.
front
()
==
"one"
&&
cb
.
back
()
==
"three"
);
}
void
testCase4
(){
tsCB
<
std
::
string
,
3
>
cb
(
1
);
assert
(
cb
.
front
()
==
std
::
string
());
cb
.
push_back
(
"zxh"
);
cb
.
push_back
(
"jwl"
);
assert
(
cb
.
back
()
==
"jwl"
);
cb
.
pop_front
();
assert
(
cb
.
front
()
==
"zxh"
);
}
void
testCase5
(){
tsCB
<
int
,
3
>
cb1
(
3
),
cb2
(
3
);
assert
(
cb1
==
cb2
);
assert
(
!
(
cb1
!=
cb2
));
cb1
[
0
]
=
-
1
;
assert
(
!
(
cb1
==
cb2
));
assert
(
cb1
!=
cb2
);
}
void
testCase6
(){
std
::
string
arr
[]
=
{
"1"
,
"2"
,
"3"
};
tsCB
<
std
::
string
,
3
>
cb
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
std
::
cout
<<
cb
<<
std
::
endl
;
}
}
}
//using namespace TinySTL::CircularBufferTest;
//int main(){
// testCase1();
// testCase2();
// testCase3();
// testCase4();
// testCase5();
// testCase6();
//
// system("pause");
// return 0;
//}
\ No newline at end of file
TinySTL/Test/CircularBufferTest.h
0 → 100644
浏览文件 @
13abfa51
#ifndef _CIRCULAR_BUFFER_TEST_H_
#define _CIRCULAR_BUFFER_TEST_H_
#include "TestUtil.h"
#include "../CircularBuffer.h"
#include <cassert>
#include <string>
#include <iostream>
namespace
TinySTL
{
namespace
CircularBufferTest
{
template
<
class
T
,
size_t
N
>
using
tsCB
=
TinySTL
::
circular_buffer
<
T
,
N
>
;
template
<
class
T
,
size_t
N
>
bool
circular_buffer_equal
(
tsCB
<
T
,
N
>&
cb1
,
tsCB
<
T
,
N
>
cb2
){
auto
it1
=
cb1
.
first
(),
it2
=
cb2
.
first
();
for
(;
it1
!=
cb1
.
last
()
&&
it2
!=
cb1
.
last
();
++
it1
,
++
it2
){
if
(
*
it1
!=
*
it2
)
return
false
;
}
return
(
it1
==
cb1
.
last
()
&&
it2
==
cb2
.
last
()
&&
(
*
(
cb1
.
last
())
==
*
(
cb2
.
last
())));
}
void
testCase1
();
void
testCase2
();
void
testCase3
();
void
testCase4
();
void
testCase5
();
void
testCase6
();
}
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录