Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
TinySTL
提交
bff17935
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 搜索 >>
提交
bff17935
编写于
3月 14, 2015
作者:
邹
邹晓航
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
消去自动化测试的屏幕输出
上级
ab9b0922
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
136 addition
and
75 deletion
+136
-75
TinySTL/Test/BitmapTest.cpp
TinySTL/Test/BitmapTest.cpp
+6
-6
TinySTL/Test/CircularBufferTest.cpp
TinySTL/Test/CircularBufferTest.cpp
+6
-1
TinySTL/Test/GraphTest.cpp
TinySTL/Test/GraphTest.cpp
+64
-10
TinySTL/Test/PairTest.cpp
TinySTL/Test/PairTest.cpp
+8
-13
TinySTL/Test/StringTest.cpp
TinySTL/Test/StringTest.cpp
+23
-22
TinySTL/Test/StringTest.h
TinySTL/Test/StringTest.h
+0
-1
TinySTL/Test/VectorTest.cpp
TinySTL/Test/VectorTest.cpp
+24
-22
TinySTL/TestData/string_test.txt
TinySTL/TestData/string_test.txt
+1
-0
TinySTL/TinySTL.vcxproj
TinySTL/TinySTL.vcxproj
+1
-0
TinySTL/TinySTL.vcxproj.filters
TinySTL/TinySTL.vcxproj.filters
+3
-0
未找到文件。
TinySTL/Test/BitmapTest.cpp
浏览文件 @
bff17935
...
...
@@ -15,22 +15,22 @@ namespace TinySTL{
void
testCase2
(){
bitmap
<
8
>
bt1
,
bt2
;
bt1
.
set
();
cout
<<
bt1
<<
endl
;
assert
(
bt1
.
to_string
()
==
"11111111"
)
;
bt1
.
reset
();
cout
<<
bt1
<<
endl
;
assert
(
bt1
.
to_string
()
==
"00000000"
)
;
bt2
.
set
(
0
);
bt2
.
set
(
2
);
bt2
.
set
(
4
);
cout
<<
bt2
<<
endl
;
assert
(
bt2
.
to_string
()
==
"10101000"
)
;
bt2
.
reset
(
0
);
bt2
.
reset
(
2
);
bt2
.
reset
(
4
);
cout
<<
bt2
<<
endl
;
assert
(
bt2
.
to_string
()
==
"00000000"
)
;
}
void
testCase3
(){
bitmap
<
8
>
bt
;
bt
.
flip
();
cout
<<
bt
<<
endl
;
assert
(
bt
.
to_string
()
==
"11111111"
)
;
bt
.
flip
(
0
);
cout
<<
bt
<<
endl
;
assert
(
bt
.
to_string
()
==
"01111111"
)
;
}
void
testCase4
(){
bitmap
<
8
>
bt
;
...
...
TinySTL/Test/CircularBufferTest.cpp
浏览文件 @
bff17935
#include "CircularBufferTest.h"
#include <sstream>
namespace
TinySTL
{
namespace
CircularBufferTest
{
void
testCase1
(){
...
...
@@ -66,7 +68,10 @@ namespace TinySTL{
void
testCase6
(){
std
::
string
arr
[]
=
{
"1"
,
"2"
,
"3"
};
tsCB
<
std
::
string
,
3
>
cb
(
std
::
begin
(
arr
),
std
::
end
(
arr
));
std
::
cout
<<
cb
<<
std
::
endl
;
std
::
ostringstream
os
;
os
<<
cb
;
assert
(
os
.
str
()
==
"(1, 2, 3)"
);
}
...
...
TinySTL/Test/GraphTest.cpp
浏览文件 @
bff17935
#include "GraphTest.h"
#include <sstream>
#include <fstream>
namespace
TinySTL
{
namespace
GraphTest
{
void
testCase1
(){
...
...
@@ -36,20 +39,71 @@ namespace TinySTL{
g
.
make_edge
(
12
,
2
);
g
.
make_edge
(
12
,
3
);
g
.
make_edge
(
12
,
0
);
std
::
cout
<<
"graph after add nodes:"
<<
std
::
endl
;
std
::
cout
<<
g
.
to_string
();
std
::
ostringstream
os
;
os
<<
g
.
to_string
();
std
::
string
res
(
R"([14,1414]:[nil]
|
[13,1313]:[nil]
|
[12,1212]:[0,0]->[3,33]->[2,22]->[nil]
|
[7,77]:[14,1414]->[13,1313]->[12,1212]->[nil]
|
[6,66]:[nil]
|
[5,55]:[nil]
|
[3,33]:[nil]
|
[2,22]:[nil]
|
[1,11]:[7,77]->[6,66]->[5,55]->[nil]
|
[0,0]:[3,33]->[2,22]->[1,11]->[nil]
|
[nil]
)"
);
assert
(
os
.
str
()
==
res
);
auto
func
=
[](
const
dGraph
<
int
,
int
>::
node_type
&
node
){
std
::
cout
<<
"["
<<
node
.
first
<<
","
<<
node
.
second
<<
"]"
<<
std
::
endl
;
std
::
ostringstream
os1
,
os2
;
auto
func1
=
[
&
os1
](
const
dGraph
<
int
,
int
>::
node_type
&
node
){
os1
<<
"["
<<
node
.
first
<<
","
<<
node
.
second
<<
"]"
;
};
auto
func2
=
[
&
os2
](
const
dGraph
<
int
,
int
>::
node_type
&
node
){
os2
<<
"["
<<
node
.
first
<<
","
<<
node
.
second
<<
"]"
;
};
std
::
cout
<<
"graph DFS from node(1, 11):"
<<
std
::
endl
;
g
.
DFS
(
1
,
func
);
std
::
cout
<<
"graph BFS from node(1, 11):"
<<
std
::
endl
;
g
.
BFS
(
1
,
func
);
res
=
R"([1,11][7,77][14,1414][13,1313][12,1212][0,0][3,33][2,22][6,66][5,55])"
;
g
.
DFS
(
1
,
func1
);
assert
(
os1
.
str
()
==
res
);
res
=
R"([1,11][7,77][6,66][5,55][14,1414][13,1313][12,1212][0,0][3,33][2,22])"
;
g
.
BFS
(
1
,
func2
);
assert
(
os2
.
str
()
==
res
);
std
::
cout
<<
"graph after delete node(7, 77):"
<<
std
::
endl
;
std
::
ostringstream
os3
;
g
.
delete_node
(
dGraph
<
int
,
int
>::
node_type
(
7
,
77
));
std
::
cout
<<
g
.
to_string
();
os3
<<
g
.
to_string
();
res
=
R"([14,1414]:[nil]
|
[13,1313]:[nil]
|
[12,1212]:[0,0]->[3,33]->[2,22]->[nil]
|
[6,66]:[nil]
|
[5,55]:[nil]
|
[3,33]:[nil]
|
[2,22]:[nil]
|
[1,11]:[6,66]->[5,55]->[nil]
|
[0,0]:[3,33]->[2,22]->[1,11]->[nil]
|
[nil]
)"
;
assert
(
os3
.
str
()
==
res
);
}
void
testCase3
(){
dGraph
<
int
,
int
>
g
;
...
...
TinySTL/Test/PairTest.cpp
浏览文件 @
bff17935
...
...
@@ -29,15 +29,12 @@ namespace TinySTL{
TinySTL
::
pair
<
int
,
char
>
foo
(
10
,
'z'
);
TinySTL
::
pair
<
int
,
char
>
bar
(
90
,
'a'
);
//foo and bar are not equal
//foo is less than bar
//foo is less than or equal to bar
if
(
foo
==
bar
)
std
::
cout
<<
"foo and bar are equal
\n
"
;
if
(
foo
!=
bar
)
std
::
cout
<<
"foo and bar are not equal
\n
"
;
if
(
foo
<
bar
)
std
::
cout
<<
"foo is less than bar
\n
"
;
if
(
foo
>
bar
)
std
::
cout
<<
"foo is greater than bar
\n
"
;
if
(
foo
<=
bar
)
std
::
cout
<<
"foo is less than or equal to bar
\n
"
;
if
(
foo
>=
bar
)
std
::
cout
<<
"foo is greater than or equal to bar
\n
"
;
assert
(
!
(
foo
==
bar
));
assert
(
foo
!=
bar
);
assert
(
foo
<
bar
);
assert
(
!
(
foo
>
bar
));
assert
(
foo
<=
bar
);
assert
(
!
(
foo
>=
bar
));
}
void
testCase5
(){
TinySTL
::
pair
<
int
,
char
>
foo
(
10
,
'z'
);
...
...
@@ -45,10 +42,8 @@ namespace TinySTL{
foo
.
swap
(
bar
);
std
::
cout
<<
"foo : ("
<<
foo
.
first
<<
", "
<<
foo
.
second
<<
")"
<<
std
::
endl
;
std
::
cout
<<
"bar : ("
<<
bar
.
first
<<
", "
<<
bar
.
second
<<
")"
<<
std
::
endl
;
//TinySTL::Test::print_container(foo);
//TinySTL::Test::print_container(bar);
assert
(
foo
.
first
==
90
&&
foo
.
second
==
'a'
);
assert
(
bar
.
first
==
10
&&
bar
.
second
==
'z'
);
}
...
...
TinySTL/Test/StringTest.cpp
浏览文件 @
bff17935
#include "StringTest.h"
#include <fstream>
namespace
TinySTL
{
namespace
StringTest
{
...
...
@@ -65,12 +67,16 @@ namespace TinySTL{
}
void
testCase4
(){
tsStr
str
(
"Test string"
);
for
(
tsStr
::
iterator
it
=
str
.
begin
();
it
!=
str
.
end
();
++
it
)
std
::
cout
<<
*
it
;
std
::
cout
<<
'\n'
;
for
(
tsStr
::
reverse_iterator
it
=
str
.
rbegin
();
it
!=
str
.
rend
();
++
it
)
std
::
cout
<<
*
it
;
std
::
cout
<<
'\n'
;
stdStr
s
(
str
.
begin
(),
str
.
end
());
auto
i
=
0
;
for
(
tsStr
::
iterator
it
=
str
.
begin
();
it
!=
str
.
end
();
++
it
,
++
i
){
assert
(
*
it
==
s
[
i
]);
}
i
=
s
.
size
()
-
1
;
for
(
tsStr
::
reverse_iterator
it
=
str
.
rbegin
();
it
!=
str
.
rend
();
++
it
,
--
i
){
assert
(
*
it
==
s
[
i
]);
}
}
void
testCase5
(){
tsStr
s
;
...
...
@@ -121,11 +127,11 @@ namespace TinySTL{
s
.
resize
(
10
);
for
(
auto
i
=
0
;
i
!=
s
.
size
();
++
i
)
s
[
i
]
=
'a'
+
i
;
TinySTL
::
Test
::
print_container
(
s
);
assert
(
s
==
"abcdefghij"
);
s
.
back
()
=
'Z'
;
s
.
front
()
=
'A'
;
TinySTL
::
Test
::
print_container
(
s
);
assert
(
s
==
"AbcdefghiZ"
);
}
void
testCase10
(){
stdStr
s1
;
...
...
@@ -295,15 +301,15 @@ namespace TinySTL{
tsStr
seller
(
"goods"
);
seller
.
swap
(
buyer
);
TinySTL
::
Test
::
print_container
(
buyer
,
"buyer
"
);
TinySTL
::
Test
::
print_container
(
seller
,
"seller
"
);
assert
(
seller
==
"money
"
);
assert
(
buyer
==
"goods
"
);
}
void
testCase18
(){
char
buffer
[
20
];
tsStr
str
(
"Test string..."
);
std
::
size_t
length
=
str
.
copy
(
buffer
,
6
,
5
);
buffer
[
length
]
=
'\0'
;
std
::
cout
<<
"buffer contains: "
<<
buffer
<<
'\n'
;
std
::
equal
(
std
::
begin
(
buffer
),
std
::
end
(
buffer
),
str
.
begin
())
;
}
void
testCase19
(){
tsStr
str
(
"There are two needles in this haystack with needles."
);
...
...
@@ -432,17 +438,13 @@ namespace TinySTL{
}
void
testCase29
(){
tsStr
name
;
std
::
ifstream
in
(
".
\\
TestData
\\
string_test.txt"
);
std
::
cout
<<
"Please, enter your name: "
;
std
::
cin
>>
name
;
std
::
cout
<<
"Hello, "
<<
name
<<
"!
\n
"
;
}
void
testCase30
(){
tsStr
name
;
std
::
cout
<<
"Please, enter your full name: "
;
TinySTL
::
getline
(
std
::
cin
,
name
);
std
::
cout
<<
"Hello, "
<<
name
<<
"!
\n
"
;
if
(
in
){
in
>>
name
;
assert
(
name
==
"zouxiaohang"
);
in
.
close
();
}
}
void
testAllCases
(){
...
...
@@ -475,7 +477,6 @@ namespace TinySTL{
testCase27
();
testCase28
();
testCase29
();
testCase30
();
}
}
}
\ No newline at end of file
TinySTL/Test/StringTest.h
浏览文件 @
bff17935
...
...
@@ -43,7 +43,6 @@ namespace TinySTL{
void
testCase27
();
void
testCase28
();
void
testCase29
();
void
testCase30
();
void
testAllCases
();
}
...
...
TinySTL/Test/VectorTest.cpp
浏览文件 @
bff17935
...
...
@@ -51,15 +51,15 @@ namespace TinySTL{
tsVec
<
int
>
myvector
;
for
(
int
i
=
1
;
i
<=
5
;
i
++
)
myvector
.
push_back
(
i
);
std
::
cout
<<
"myvector contains:"
;
for
(
tsVec
<
int
>::
iterator
it
=
myvector
.
begin
();
it
!=
myvector
.
end
();
++
it
)
std
::
cout
<<
' '
<<
*
it
;
std
::
cout
<<
'\n'
;
std
::
cout
<<
"myvector contains:"
;
for
(
tsVec
<
int
>::
const_iterator
it
=
myvector
.
cbegin
();
it
!=
myvector
.
cend
();
++
it
)
std
::
cout
<<
' '
<<
*
it
;
std
::
cout
<<
'\n'
;
auto
i
=
1
;
for
(
tsVec
<
int
>::
iterator
it
=
myvector
.
begin
();
it
!=
myvector
.
end
();
++
it
,
++
i
){
assert
(
*
it
==
i
)
;
}
i
=
1
;
for
(
tsVec
<
int
>::
const_iterator
it
=
myvector
.
cbegin
();
it
!=
myvector
.
cend
();
++
it
,
++
i
){
assert
(
*
it
==
i
)
;
}
}
void
testCase5
(){
tsVec
<
int
>
myvector
(
5
);
// 5 default-constructed ints
...
...
@@ -68,14 +68,15 @@ namespace TinySTL{
for
(;
rit
!=
myvector
.
rend
();
++
rit
)
*
rit
=
++
i
;
std
::
cout
<<
"myvector contains:"
;
for
(
tsVec
<
int
>::
iterator
it
=
myvector
.
begin
();
it
!=
myvector
.
end
();
++
it
)
std
::
cout
<<
' '
<<
*
it
;
std
::
cout
<<
'\n'
;
std
::
cout
<<
"myvector contains(reverse order):"
;
for
(
tsVec
<
int
>::
reverse_iterator
it
=
myvector
.
rbegin
();
it
!=
myvector
.
rend
();
++
it
)
std
::
cout
<<
' '
<<
*
it
;
std
::
cout
<<
'\n'
;
i
=
5
;
for
(
tsVec
<
int
>::
iterator
it
=
myvector
.
begin
();
it
!=
myvector
.
end
();
++
it
,
--
i
){
assert
(
*
it
==
i
);
}
i
=
1
;
for
(
tsVec
<
int
>::
reverse_iterator
it
=
myvector
.
rbegin
();
it
!=
myvector
.
rend
();
++
it
,
++
i
){
assert
(
*
it
==
i
);
}
}
void
testCase6
(){
tsVec
<
int
>
v
(
11
,
0
);
...
...
@@ -121,13 +122,14 @@ namespace TinySTL{
}
void
testCase10
(){
tsVec
<
int
>
foo
(
3
,
100
);
// three ints with a value of 100
tsVec
<
int
>
bar
(
5
,
200
);
// five ints with a value of 200
tsVec
<
int
>
bar
(
2
,
200
);
// five ints with a value of 200
assert
(
TinySTL
::
Test
::
container_equal
(
foo
,
stdVec
<
int
>
{
100
,
100
,
100
}));
assert
(
TinySTL
::
Test
::
container_equal
(
bar
,
stdVec
<
int
>
{
200
,
200
}));
TinySTL
::
Test
::
print_container
(
foo
,
"foo"
);
TinySTL
::
Test
::
print_container
(
bar
,
"bar"
);
foo
.
swap
(
bar
);
TinySTL
::
Test
::
print_container
(
foo
,
"foo"
);
TinySTL
::
Test
::
print_container
(
bar
,
"bar"
);
assert
(
TinySTL
::
Test
::
container_equal
(
bar
,
stdVec
<
int
>
{
100
,
100
,
100
})
);
assert
(
TinySTL
::
Test
::
container_equal
(
foo
,
stdVec
<
int
>
{
200
,
200
})
);
}
void
testCase11
(){
stdVec
<
std
::
string
>
v1
;
...
...
TinySTL/TestData/string_test.txt
0 → 100644
浏览文件 @
bff17935
zouxiaohang
\ No newline at end of file
TinySTL/TinySTL.vcxproj
浏览文件 @
bff17935
...
...
@@ -175,6 +175,7 @@
<Image
Include=
"ScreenShots\trie_tree.png"
/>
</ItemGroup>
<ItemGroup>
<Text
Include=
"TestData\string_test.txt"
/>
<Text
Include=
"TestData\trie_tree_test.txt"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
...
...
TinySTL/TinySTL.vcxproj.filters
浏览文件 @
bff17935
...
...
@@ -300,5 +300,8 @@
<Text
Include=
"TestData\trie_tree_test.txt"
>
<Filter>
TestData
</Filter>
</Text>
<Text
Include=
"TestData\string_test.txt"
>
<Filter>
TestData
</Filter>
</Text>
</ItemGroup>
</Project>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录