Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
fb7f635e
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 搜索 >>
提交
fb7f635e
编写于
1月 07, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成deque的单元测试
上级
1e16e18e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
135 addition
and
0 deletion
+135
-0
TinySTL/Test/DequeTest.cpp
TinySTL/Test/DequeTest.cpp
+103
-0
TinySTL/Test/DequeTest.h
TinySTL/Test/DequeTest.h
+30
-0
TinySTL/main.cpp
TinySTL/main.cpp
+2
-0
未找到文件。
TinySTL/Test/DequeTest.cpp
0 → 100644
浏览文件 @
fb7f635e
#include "DequeTest.h"
namespace
TinySTL
{
namespace
DequeTest
{
void
testCase1
(){
stdDQ
<
int
>
dq1
(
10
,
0
);
tsDQ
<
int
>
dq2
(
10
,
0
);
assert
(
TinySTL
::
Test
::
container_equal
(
dq1
,
dq2
));
int
arr
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
stdDQ
<
int
>
dq3
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
tsDQ
<
int
>
dq4
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
assert
(
TinySTL
::
Test
::
container_equal
(
dq3
,
dq4
));
auto
dq5
(
dq1
);
auto
dq6
(
dq2
);
assert
(
TinySTL
::
Test
::
container_equal
(
dq5
,
dq6
));
auto
dq7
=
dq3
;
auto
dq8
=
dq4
;
assert
(
TinySTL
::
Test
::
container_equal
(
dq7
,
dq8
));
auto
dq9
=
std
::
move
(
dq7
);
auto
dq10
=
std
::
move
(
dq8
);
assert
(
TinySTL
::
Test
::
container_equal
(
dq9
,
dq10
));
}
void
testCase2
(){
tsDQ
<
int
>
dq1
;
assert
(
dq1
.
empty
());
assert
(
dq1
.
size
()
==
0
);
tsDQ
<
int
>
dq2
(
10
,
0
);
assert
(
!
dq2
.
empty
());
assert
(
dq2
.
size
()
==
10
);
}
void
testCase3
(){
stdDQ
<
std
::
string
>
dq1
(
10
,
"10"
);
tsDQ
<
std
::
string
>
dq2
(
10
,
"10"
);
dq1
[
0
]
=
"0"
;
dq1
[
9
]
=
"9"
;
dq2
[
0
]
=
"0"
;
dq2
[
9
]
=
"9"
;
assert
(
dq1
.
front
()
==
dq2
.
front
());
assert
(
dq1
.
back
()
==
dq2
.
back
());
}
void
testCase4
(){
stdDQ
<
int
>
dq1
;
tsDQ
<
int
>
dq2
;
for
(
auto
i
=
0
;
i
!=
10
;
++
i
){
dq1
.
push_back
(
i
);
dq2
.
push_back
(
i
);
}
assert
(
TinySTL
::
Test
::
container_equal
(
dq1
,
dq2
));
for
(
auto
i
=
10
;
i
!=
20
;
++
i
){
dq1
.
push_front
(
i
);
dq2
.
push_front
(
i
);
}
assert
(
TinySTL
::
Test
::
container_equal
(
dq1
,
dq2
));
for
(
auto
i
=
0
;
i
!=
5
;
++
i
){
dq1
.
pop_back
();
dq2
.
pop_back
();
}
assert
(
TinySTL
::
Test
::
container_equal
(
dq1
,
dq2
));
for
(
auto
i
=
0
;
i
!=
5
;
++
i
){
dq1
.
pop_front
();
dq2
.
pop_front
();
}
assert
(
TinySTL
::
Test
::
container_equal
(
dq1
,
dq2
));
}
void
testCase5
(){
int
arr
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
tsDQ
<
int
>
foo
(
arr
,
arr
+
3
),
bar
(
arr
+
3
,
arr
+
10
);
assert
(
foo
.
size
()
==
3
&&
bar
.
size
()
==
7
);
foo
.
swap
(
bar
);
assert
(
foo
.
size
()
==
7
&&
bar
.
size
()
==
3
);
TinySTL
::
swap
(
foo
,
bar
);
assert
(
foo
.
size
()
==
3
&&
bar
.
size
()
==
7
);
}
void
testCase6
(){
int
arr
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
tsDQ
<
int
>
foo1
(
arr
,
arr
+
3
),
bar
(
arr
+
3
,
arr
+
10
);
assert
(
foo1
!=
bar
);
auto
foo2
=
bar
;
assert
(
foo2
==
bar
);
}
void
testAllCases
(){
testCase1
();
testCase2
();
testCase3
();
testCase4
();
testCase5
();
testCase6
();
}
}
}
\ No newline at end of file
TinySTL/Test/DequeTest.h
0 → 100644
浏览文件 @
fb7f635e
#ifndef _DEQUE_TEST_H_
#define _DEQUE_TEST_H_
#include "TestUtil.h"
#include "../Deque.h"
#include <deque>
#include <cassert>
#include <string>
namespace
TinySTL
{
namespace
DequeTest
{
template
<
class
T
>
using
stdDQ
=
std
::
deque
<
T
>
;
template
<
class
T
>
using
tsDQ
=
TinySTL
::
deque
<
T
>
;
void
testCase1
();
void
testCase2
();
void
testCase3
();
void
testCase4
();
void
testCase5
();
void
testCase6
();
void
testAllCases
();
}
}
#endif
\ No newline at end of file
TinySTL/main.cpp
浏览文件 @
fb7f635e
...
...
@@ -6,6 +6,7 @@
#include "Test\AlgorithmTest.h"
#include "Test\BitmapTest.h"
#include "Test\CircularBufferTest.h"
#include "Test\DequeTest.h"
#include "Test\PairTest.h"
#include "Test\PriorityQueueTest.h"
#include "Test\QueueTest.h"
...
...
@@ -21,6 +22,7 @@ int main(){
TinySTL
::
AlgorithmTest
::
testAllCases
();
TinySTL
::
BitmapTest
::
testAllCases
();
TinySTL
::
CircularBufferTest
::
testAllCases
();
TinySTL
::
DequeTest
::
testAllCases
();
TinySTL
::
PairTest
::
testAllCases
();
TinySTL
::
PriorityQueueTest
::
testAllCases
();
TinySTL
::
QueueTest
::
testAllCases
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录