Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
60f4e6f4
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 搜索 >>
提交
60f4e6f4
编写于
1月 20, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成Unordered_set的测试
上级
440a6fc1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
129 addition
and
1 deletion
+129
-1
TinySTL/Test/Unordered_setTest.cpp
TinySTL/Test/Unordered_setTest.cpp
+95
-0
TinySTL/Test/Unordered_setTest.h
TinySTL/Test/Unordered_setTest.h
+32
-0
TinySTL/main.cpp
TinySTL/main.cpp
+2
-1
未找到文件。
TinySTL/Test/Unordered_setTest.cpp
0 → 100644
浏览文件 @
60f4e6f4
#include "Unordered_setTest.h"
namespace
TinySTL
{
namespace
Unordered_setTest
{
template
<
class
Container1
,
class
Container2
>
bool
container_equal
(
Container1
&
con1
,
Container2
&
con2
){
std
::
vector
<
typename
Container1
::
value_type
>
vec1
,
vec2
;
for
(
auto
&
item
:
con1
){
vec1
.
push_back
(
item
);
}
for
(
auto
&
item
:
con2
){
vec2
.
push_back
(
item
);
}
std
::
sort
(
vec1
.
begin
(),
vec1
.
end
());
std
::
sort
(
vec2
.
begin
(),
vec2
.
end
());
return
vec1
==
vec2
;
}
void
testCase1
(){
stdUst
<
int
>
ust1
(
10
);
tsUst
<
int
>
ust2
(
10
);
assert
(
container_equal
(
ust1
,
ust2
));
int
arr
[]
=
{
0
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
stdUst
<
int
>
ust3
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
tsUst
<
int
>
ust4
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
assert
(
container_equal
(
ust3
,
ust4
));
auto
ust5
(
ust3
);
auto
ust6
(
ust4
);
assert
(
container_equal
(
ust5
,
ust6
));
auto
ust7
=
ust3
;
auto
ust8
=
ust4
;
assert
(
container_equal
(
ust7
,
ust8
));
}
void
testCase2
(){
tsUst
<
int
>
ust1
(
10
);
assert
(
ust1
.
empty
());
assert
(
ust1
.
size
()
==
0
);
int
arr
[]
=
{
0
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
tsUst
<
int
>
ust2
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
assert
(
!
ust2
.
empty
());
assert
(
ust2
.
size
()
==
10
);
}
void
testCase3
(){
tsUst
<
std
::
string
>
ust1
(
10
);
stdUst
<
std
::
string
>
ust2
(
10
);
std
::
random_device
rd
;
for
(
auto
i
=
0
;
i
!=
100
;
++
i
){
auto
n
=
std
::
to_string
(
rd
()
%
65536
);
ust1
.
insert
(
n
);
ust2
.
insert
(
n
);
}
assert
(
container_equal
(
ust1
,
ust2
));
tsUst
<
int
>
ust3
(
10
);
stdUst
<
int
>
ust4
(
10
);
std
::
vector
<
int
>
v
(
200
);
std
::
generate
(
v
.
begin
(),
v
.
end
(),
[
&
rd
](){
return
rd
()
%
65536
;
});
ust3
.
insert
(
v
.
begin
(),
v
.
end
());
ust4
.
insert
(
v
.
begin
(),
v
.
end
());
assert
(
container_equal
(
ust3
,
ust4
));
}
void
testCase4
(){
int
arr
[]
=
{
0
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
stdUst
<
int
>
ust1
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
tsUst
<
int
>
ust2
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
ust1
.
erase
(
9
);
auto
n
=
ust2
.
erase
(
9
);
assert
(
n
==
1
);
ust1
.
erase
(
7
);
auto
it
=
ust2
.
find
(
7
);
it
=
ust2
.
erase
(
it
);
assert
(
it
!=
ust2
.
end
());
assert
(
container_equal
(
ust1
,
ust2
));
}
void
testCase5
(){
int
arr
[]
=
{
0
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
7
,
8
,
9
};
tsUst
<
int
>
ust
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
assert
(
ust
.
find
(
0
)
!=
ust
.
end
());
assert
(
ust
.
count
(
10
)
==
0
);
}
void
testAllCases
(){
testCase1
();
testCase2
();
testCase3
();
testCase4
();
testCase5
();
}
}
}
\ No newline at end of file
TinySTL/Test/Unordered_setTest.h
0 → 100644
浏览文件 @
60f4e6f4
#ifndef _UNORDERED_SET_TEST_H_
#define _UNORDERED_SET_TEST_H_
#include "TestUtil.h"
#include "../Unordered_set.h"
#include <unordered_set>
#include <algorithm>
#include <cassert>
#include <random>
#include <string>
#include <vector>
namespace
TinySTL
{
namespace
Unordered_setTest
{
template
<
class
T
>
using
stdUst
=
std
::
unordered_set
<
T
>
;
template
<
class
T
>
using
tsUst
=
TinySTL
::
Unordered_set
<
T
>
;
void
testCase1
();
void
testCase2
();
void
testCase3
();
void
testCase4
();
void
testCase5
();
void
testAllCases
();
}
}
#endif
\ No newline at end of file
TinySTL/main.cpp
浏览文件 @
60f4e6f4
...
@@ -16,9 +16,9 @@
...
@@ -16,9 +16,9 @@
#include "Test\StackTest.h"
#include "Test\StackTest.h"
#include "Test\StringTest.h"
#include "Test\StringTest.h"
#include "Test\SuffixArrayTest.h"
#include "Test\SuffixArrayTest.h"
#include "Test\Unordered_setTest.h"
#include "Test\VectorTest.h"
#include "Test\VectorTest.h"
using
namespace
std
;
using
namespace
TinySTL
::
Profiler
;
using
namespace
TinySTL
::
Profiler
;
int
main
(){
int
main
(){
...
@@ -35,6 +35,7 @@ int main(){
...
@@ -35,6 +35,7 @@ int main(){
TinySTL
::
StackTest
::
testAllCases
();
TinySTL
::
StackTest
::
testAllCases
();
TinySTL
::
StringTest
::
testAllCases
();
TinySTL
::
StringTest
::
testAllCases
();
TinySTL
::
SuffixArrayTest
::
testAllCases
();
TinySTL
::
SuffixArrayTest
::
testAllCases
();
TinySTL
::
Unordered_setTest
::
testAllCases
();
TinySTL
::
VectorTest
::
testAllCases
();
TinySTL
::
VectorTest
::
testAllCases
();
system
(
"pause"
);
system
(
"pause"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录