Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
666f2899
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 搜索 >>
提交
666f2899
编写于
1月 14, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成二叉搜索树的测试
上级
96a1c5ec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
96 addition
and
0 deletion
+96
-0
TinySTL/Test/BinarySearchTreeTest.cpp
TinySTL/Test/BinarySearchTreeTest.cpp
+70
-0
TinySTL/Test/BinarySearchTreeTest.h
TinySTL/Test/BinarySearchTreeTest.h
+24
-0
TinySTL/main.cpp
TinySTL/main.cpp
+2
-0
未找到文件。
TinySTL/Test/BinarySearchTreeTest.cpp
0 → 100644
浏览文件 @
666f2899
#include "BinarySearchTreeTest.h"
namespace
TinySTL
{
namespace
BinarySearchTreeTest
{
template
<
class
Container1
,
class
Container2
>
bool
container_equal
(
const
Container1
&
con1
,
const
Container2
&
con2
){
auto
first1
=
con1
.
cbegin
(),
last1
=
con1
.
cend
();
auto
first2
=
con2
.
cbegin
(),
last2
=
con2
.
cend
();
for
(;
first1
!=
last1
&&
first2
!=
last2
;
++
first1
,
++
first2
){
if
(
*
first1
!=
*
first2
)
return
false
;
}
return
(
first1
==
last1
&&
first2
==
last2
);
}
void
testCase1
(){
tsBst
<
std
::
string
>
bst
;
assert
(
bst
.
empty
());
assert
(
bst
.
size
()
==
0
);
bst
.
insert
(
"1"
);
assert
(
!
bst
.
empty
());
assert
(
bst
.
size
()
==
1
);
}
void
testCase2
(){
tsBst
<
int
>
bst
;
for
(
auto
i
=
0
;
i
!=
100
;
++
i
)
bst
.
insert
(
i
);
assert
(
bst
.
height
()
==
100
);
}
void
testCase3
(){
tsBst
<
int
>
bst
;
std
::
vector
<
int
>
v
;
std
::
random_device
rd
;
for
(
auto
i
=
0
;
i
!=
10
;
++
i
){
auto
r
=
rd
()
%
65536
;
bst
.
insert
(
r
);
v
.
push_back
(
r
);
}
std
::
sort
(
v
.
begin
(),
v
.
end
());
v
.
erase
(
std
::
unique
(
v
.
begin
(),
v
.
end
()),
v
.
end
());
assert
(
container_equal
(
bst
,
v
));
tsBst
<
int
>
bst1
;
bst1
.
insert
(
v
.
begin
(),
v
.
end
());
assert
(
container_equal
(
bst1
,
v
));
}
void
testCase4
(){
tsBst
<
int
>
bst
;
for
(
auto
i
=
0
;
i
!=
10
;
++
i
)
bst
.
insert
(
i
);
assert
(
*
bst
.
find
(
5
)
==
5
);
assert
(
*
bst
.
find_min
()
==
0
);
assert
(
*
bst
.
find_max
()
==
9
);
}
void
testAllCases
(){
testCase1
();
testCase2
();
testCase3
();
testCase4
();
}
}
}
\ No newline at end of file
TinySTL/Test/BinarySearchTreeTest.h
0 → 100644
浏览文件 @
666f2899
#ifndef _BINARY_SEARCH_TREE_TEST_H_
#define _BINARY_SEARCH_TREE_TEST_H_
#include "TestUtil.h"
#include "../BinarySearchTree.h"
#include <algorithm>
#include <cassert>
#include <random>
#include <string>
#include <vector>
namespace
TinySTL
{
namespace
BinarySearchTreeTest
{
template
<
class
T
>
using
tsBst
=
TinySTL
::
binary_search_tree
<
T
>
;
void
testAllCases
();
}
}
#endif
\ No newline at end of file
TinySTL/main.cpp
浏览文件 @
666f2899
...
...
@@ -5,6 +5,7 @@
#include "Test\AlgorithmTest.h"
#include "Test\BitmapTest.h"
#include "Test\BinarySearchTreeTest.h"
#include "Test\CircularBufferTest.h"
#include "Test\DequeTest.h"
#include "Test\ListTest.h"
...
...
@@ -22,6 +23,7 @@ using namespace TinySTL::Profiler;
int
main
(){
TinySTL
::
AlgorithmTest
::
testAllCases
();
TinySTL
::
BitmapTest
::
testAllCases
();
TinySTL
::
BinarySearchTreeTest
::
testAllCases
();
TinySTL
::
CircularBufferTest
::
testAllCases
();
TinySTL
::
DequeTest
::
testAllCases
();
TinySTL
::
ListTest
::
testAllCases
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录