Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3d9d96b6
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3d9d96b6
编写于
5月 22, 2016
作者:
S
Srinivas Reddy Thatiparthy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
run rustfmt on libcollections test module
上级
da419209
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
522 addition
and
424 deletion
+522
-424
src/libcollectionstest/btree/map.rs
src/libcollectionstest/btree/map.rs
+74
-44
src/libcollectionstest/enum_set.rs
src/libcollectionstest/enum_set.rs
+88
-27
src/libcollectionstest/linked_list.rs
src/libcollectionstest/linked_list.rs
+23
-22
src/libcollectionstest/slice.rs
src/libcollectionstest/slice.rs
+174
-192
src/libcollectionstest/string.rs
src/libcollectionstest/string.rs
+51
-66
src/libcollectionstest/vec.rs
src/libcollectionstest/vec.rs
+34
-22
src/libcollectionstest/vec_deque.rs
src/libcollectionstest/vec_deque.rs
+78
-51
未找到文件。
src/libcollectionstest/btree/map.rs
浏览文件 @
3d9d96b6
...
...
@@ -9,7 +9,7 @@
// except according to those terms.
use
std
::
collections
::
BTreeMap
;
use
std
::
collections
::
Bound
::{
Excluded
,
Included
,
Unbounded
,
self
};
use
std
::
collections
::
Bound
::{
self
,
Excluded
,
Included
,
Unbounded
};
use
std
::
collections
::
btree_map
::
Entry
::{
Occupied
,
Vacant
};
use
std
::
rc
::
Rc
;
...
...
@@ -20,41 +20,41 @@ fn test_basic_large() {
assert_eq!
(
map
.len
(),
0
);
for
i
in
0
..
size
{
assert_eq!
(
map
.insert
(
i
,
10
*
i
),
None
);
assert_eq!
(
map
.insert
(
i
,
10
*
i
),
None
);
assert_eq!
(
map
.len
(),
i
+
1
);
}
for
i
in
0
..
size
{
assert_eq!
(
map
.get
(
&
i
)
.unwrap
(),
&
(
i
*
10
));
assert_eq!
(
map
.get
(
&
i
)
.unwrap
(),
&
(
i
*
10
));
}
for
i
in
size
..
size
*
2
{
for
i
in
size
..
size
*
2
{
assert_eq!
(
map
.get
(
&
i
),
None
);
}
for
i
in
0
..
size
{
assert_eq!
(
map
.insert
(
i
,
100
*
i
),
Some
(
10
*
i
));
assert_eq!
(
map
.insert
(
i
,
100
*
i
),
Some
(
10
*
i
));
assert_eq!
(
map
.len
(),
size
);
}
for
i
in
0
..
size
{
assert_eq!
(
map
.get
(
&
i
)
.unwrap
(),
&
(
i
*
100
));
assert_eq!
(
map
.get
(
&
i
)
.unwrap
(),
&
(
i
*
100
));
}
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
}
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.get
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.get
(
&
(
2
*
i
+
1
))
.unwrap
(),
&
(
i
*
200
+
100
));
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.get
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.get
(
&
(
2
*
i
+
1
))
.unwrap
(),
&
(
i
*
200
+
100
));
}
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
}
}
...
...
@@ -81,7 +81,9 @@ fn test_iter() {
// Forwards
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
{
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
{
for
i
in
0
..
size
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
...
...
@@ -101,7 +103,9 @@ fn test_iter_rev() {
// Forwards
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
{
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
{
for
i
in
0
..
size
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
size
-
i
-
1
,
size
-
i
-
1
));
...
...
@@ -125,8 +129,7 @@ fn test_values_mut() {
}
let
values
:
Vec
<
String
>
=
a
.values
()
.cloned
()
.collect
();
assert_eq!
(
values
,
[
String
::
from
(
"hello!"
),
String
::
from
(
"goodbye!"
)]);
assert_eq!
(
values
,
[
String
::
from
(
"hello!"
),
String
::
from
(
"goodbye!"
)]);
}
#[test]
...
...
@@ -137,7 +140,8 @@ fn test_iter_mixed() {
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
+
DoubleEndedIterator
{
where
T
:
Iterator
<
Item
=
(
usize
,
usize
)
>
+
DoubleEndedIterator
{
for
i
in
0
..
size
/
4
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
*
2
,
Some
(
size
-
i
*
2
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
...
...
@@ -202,7 +206,7 @@ fn test_range() {
for
i
in
0
..
size
{
for
j
in
i
..
size
{
let
mut
kvs
=
map
.range
(
Included
(
&
i
),
Included
(
&
j
))
.map
(|(
&
k
,
&
v
)|
(
k
,
v
));
let
mut
pairs
=
(
i
..
j
+
1
)
.map
(|
i
|
(
i
,
i
));
let
mut
pairs
=
(
i
..
j
+
1
)
.map
(|
i
|
(
i
,
i
));
for
(
kv
,
pair
)
in
kvs
.by_ref
()
.zip
(
pairs
.by_ref
())
{
assert_eq!
(
kv
,
pair
);
...
...
@@ -242,7 +246,7 @@ fn test_borrow() {
}
#[test]
fn
test_entry
(){
fn
test_entry
()
{
let
xs
=
[(
1
,
10
),
(
2
,
20
),
(
3
,
30
),
(
4
,
40
),
(
5
,
50
),
(
6
,
60
)];
let
mut
map
:
BTreeMap
<
_
,
_
>
=
xs
.iter
()
.cloned
()
.collect
();
...
...
@@ -341,17 +345,23 @@ fn test_bad_zst() {
struct
Bad
;
impl
PartialEq
for
Bad
{
fn
eq
(
&
self
,
_
:
&
Self
)
->
bool
{
false
}
fn
eq
(
&
self
,
_
:
&
Self
)
->
bool
{
false
}
}
impl
Eq
for
Bad
{}
impl
PartialOrd
for
Bad
{
fn
partial_cmp
(
&
self
,
_
:
&
Self
)
->
Option
<
Ordering
>
{
Some
(
Ordering
::
Less
)
}
fn
partial_cmp
(
&
self
,
_
:
&
Self
)
->
Option
<
Ordering
>
{
Some
(
Ordering
::
Less
)
}
}
impl
Ord
for
Bad
{
fn
cmp
(
&
self
,
_
:
&
Self
)
->
Ordering
{
Ordering
::
Less
}
fn
cmp
(
&
self
,
_
:
&
Self
)
->
Ordering
{
Ordering
::
Less
}
}
let
mut
m
=
BTreeMap
::
new
();
...
...
@@ -368,27 +378,27 @@ fn test_clone() {
assert_eq!
(
map
.len
(),
0
);
for
i
in
0
..
size
{
assert_eq!
(
map
.insert
(
i
,
10
*
i
),
None
);
assert_eq!
(
map
.insert
(
i
,
10
*
i
),
None
);
assert_eq!
(
map
.len
(),
i
+
1
);
assert_eq!
(
map
,
map
.clone
());
}
for
i
in
0
..
size
{
assert_eq!
(
map
.insert
(
i
,
100
*
i
),
Some
(
10
*
i
));
assert_eq!
(
map
.insert
(
i
,
100
*
i
),
Some
(
10
*
i
));
assert_eq!
(
map
.len
(),
size
);
assert_eq!
(
map
,
map
.clone
());
}
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
assert_eq!
(
map
,
map
.clone
());
}
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
assert_eq!
(
map
,
map
.clone
());
}
}
...
...
@@ -398,16 +408,36 @@ fn test_clone() {
fn
test_variance
()
{
use
std
::
collections
::
btree_map
::{
Iter
,
IntoIter
,
Range
,
Keys
,
Values
};
fn
map_key
<
'new
>
(
v
:
BTreeMap
<&
'static
str
,
()
>
)
->
BTreeMap
<&
'new
str
,
()
>
{
v
}
fn
map_val
<
'new
>
(
v
:
BTreeMap
<
(),
&
'static
str
>
)
->
BTreeMap
<
(),
&
'new
str
>
{
v
}
fn
iter_key
<
'a
,
'new
>
(
v
:
Iter
<
'a
,
&
'static
str
,
()
>
)
->
Iter
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
iter_val
<
'a
,
'new
>
(
v
:
Iter
<
'a
,
(),
&
'static
str
>
)
->
Iter
<
'a
,
(),
&
'new
str
>
{
v
}
fn
into_iter_key
<
'new
>
(
v
:
IntoIter
<&
'static
str
,
()
>
)
->
IntoIter
<&
'new
str
,
()
>
{
v
}
fn
into_iter_val
<
'new
>
(
v
:
IntoIter
<
(),
&
'static
str
>
)
->
IntoIter
<
(),
&
'new
str
>
{
v
}
fn
range_key
<
'a
,
'new
>
(
v
:
Range
<
'a
,
&
'static
str
,
()
>
)
->
Range
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
range_val
<
'a
,
'new
>
(
v
:
Range
<
'a
,
(),
&
'static
str
>
)
->
Range
<
'a
,
(),
&
'new
str
>
{
v
}
fn
keys
<
'a
,
'new
>
(
v
:
Keys
<
'a
,
&
'static
str
,
()
>
)
->
Keys
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
vals
<
'a
,
'new
>
(
v
:
Values
<
'a
,
(),
&
'static
str
>
)
->
Values
<
'a
,
(),
&
'new
str
>
{
v
}
fn
map_key
<
'new
>
(
v
:
BTreeMap
<&
'static
str
,
()
>
)
->
BTreeMap
<&
'new
str
,
()
>
{
v
}
fn
map_val
<
'new
>
(
v
:
BTreeMap
<
(),
&
'static
str
>
)
->
BTreeMap
<
(),
&
'new
str
>
{
v
}
fn
iter_key
<
'a
,
'new
>
(
v
:
Iter
<
'a
,
&
'static
str
,
()
>
)
->
Iter
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
iter_val
<
'a
,
'new
>
(
v
:
Iter
<
'a
,
(),
&
'static
str
>
)
->
Iter
<
'a
,
(),
&
'new
str
>
{
v
}
fn
into_iter_key
<
'new
>
(
v
:
IntoIter
<&
'static
str
,
()
>
)
->
IntoIter
<&
'new
str
,
()
>
{
v
}
fn
into_iter_val
<
'new
>
(
v
:
IntoIter
<
(),
&
'static
str
>
)
->
IntoIter
<
(),
&
'new
str
>
{
v
}
fn
range_key
<
'a
,
'new
>
(
v
:
Range
<
'a
,
&
'static
str
,
()
>
)
->
Range
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
range_val
<
'a
,
'new
>
(
v
:
Range
<
'a
,
(),
&
'static
str
>
)
->
Range
<
'a
,
(),
&
'new
str
>
{
v
}
fn
keys
<
'a
,
'new
>
(
v
:
Keys
<
'a
,
&
'static
str
,
()
>
)
->
Keys
<
'a
,
&
'new
str
,
()
>
{
v
}
fn
vals
<
'a
,
'new
>
(
v
:
Values
<
'a
,
(),
&
'static
str
>
)
->
Values
<
'a
,
(),
&
'new
str
>
{
v
}
}
#[test]
...
...
@@ -440,7 +470,7 @@ fn test_vacant_entry_key() {
Vacant
(
e
)
=>
{
assert_eq!
(
key
,
*
e
.key
());
e
.insert
(
value
.clone
());
}
,
}
}
assert_eq!
(
a
.len
(),
1
);
assert_eq!
(
a
[
key
],
value
);
...
...
src/libcollectionstest/enum_set.rs
浏览文件 @
3d9d96b6
...
...
@@ -17,7 +17,9 @@
#[derive(Copy,
Clone,
PartialEq,
Debug)]
#[repr(usize)]
enum
Foo
{
A
,
B
,
C
A
,
B
,
C
,
}
impl
CLike
for
Foo
{
...
...
@@ -60,9 +62,8 @@ fn test_len() {
assert_eq!
(
e
.len
(),
0
);
}
///////////////////////////////////////////////////////////////////////////
// intersect
/// ////////////////////////////////////////////////////////////////////////
/// intersect
#[test]
fn
test_two_empties_do_not_intersect
()
{
let
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
...
@@ -105,9 +106,8 @@ fn test_overlapping_intersects() {
assert
!
(
!
e1
.is_disjoint
(
&
e2
));
}
///////////////////////////////////////////////////////////////////////////
// contains and contains_elem
/// ////////////////////////////////////////////////////////////////////////
/// contains and contains_elem
#[test]
fn
test_superset
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
...
@@ -141,9 +141,8 @@ fn test_contains() {
assert
!
(
!
e1
.contains
(
&
C
));
}
///////////////////////////////////////////////////////////////////////////
// iter
/// ////////////////////////////////////////////////////////////////////////
/// iter
#[test]
fn
test_iterator
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
...
@@ -157,20 +156,19 @@ fn test_iterator() {
e1
.insert
(
C
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
C
]);
assert_eq!
(
elems
,
[
A
,
C
]);
e1
.insert
(
C
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
C
]);
assert_eq!
(
elems
,
[
A
,
C
]);
e1
.insert
(
B
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
}
///////////////////////////////////////////////////////////////////////////
// operators
/// ////////////////////////////////////////////////////////////////////////
/// operators
#[test]
fn
test_operators
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
...
@@ -183,7 +181,7 @@ fn test_operators() {
let
e_union
=
e1
|
e2
;
let
elems
:
Vec
<
_
>
=
e_union
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
let
e_intersection
=
e1
&
e2
;
let
elems
:
Vec
<
_
>
=
e_intersection
.iter
()
.collect
();
...
...
@@ -201,17 +199,17 @@ fn test_operators() {
// Bitwise XOR of two sets, aka symmetric difference
let
e_symmetric_diff
=
e1
^
e2
;
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
]);
assert_eq!
(
elems
,
[
A
,
B
]);
// Another way to express symmetric difference
let
e_symmetric_diff
=
(
e1
-
e2
)
|
(
e2
-
e1
);
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
]);
assert_eq!
(
elems
,
[
A
,
B
]);
// Yet another way to express symmetric difference
let
e_symmetric_diff
=
(
e1
|
e2
)
-
(
e1
&
e2
);
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
]);
assert_eq!
(
elems
,
[
A
,
B
]);
}
#[test]
...
...
@@ -221,13 +219,76 @@ fn test_overflow() {
#[derive(Copy,
Clone)]
#[repr(usize)]
enum
Bar
{
V00
,
V01
,
V02
,
V03
,
V04
,
V05
,
V06
,
V07
,
V08
,
V09
,
V10
,
V11
,
V12
,
V13
,
V14
,
V15
,
V16
,
V17
,
V18
,
V19
,
V20
,
V21
,
V22
,
V23
,
V24
,
V25
,
V26
,
V27
,
V28
,
V29
,
V30
,
V31
,
V32
,
V33
,
V34
,
V35
,
V36
,
V37
,
V38
,
V39
,
V40
,
V41
,
V42
,
V43
,
V44
,
V45
,
V46
,
V47
,
V48
,
V49
,
V50
,
V51
,
V52
,
V53
,
V54
,
V55
,
V56
,
V57
,
V58
,
V59
,
V60
,
V61
,
V62
,
V63
,
V64
,
V65
,
V66
,
V67
,
V68
,
V69
,
V00
,
V01
,
V02
,
V03
,
V04
,
V05
,
V06
,
V07
,
V08
,
V09
,
V10
,
V11
,
V12
,
V13
,
V14
,
V15
,
V16
,
V17
,
V18
,
V19
,
V20
,
V21
,
V22
,
V23
,
V24
,
V25
,
V26
,
V27
,
V28
,
V29
,
V30
,
V31
,
V32
,
V33
,
V34
,
V35
,
V36
,
V37
,
V38
,
V39
,
V40
,
V41
,
V42
,
V43
,
V44
,
V45
,
V46
,
V47
,
V48
,
V49
,
V50
,
V51
,
V52
,
V53
,
V54
,
V55
,
V56
,
V57
,
V58
,
V59
,
V60
,
V61
,
V62
,
V63
,
V64
,
V65
,
V66
,
V67
,
V68
,
V69
,
}
impl
CLike
for
Bar
{
...
...
src/libcollectionstest/linked_list.rs
浏览文件 @
3d9d96b6
...
...
@@ -54,7 +54,7 @@ fn test_basic() {
#[cfg(test)]
fn
generate_test
()
->
LinkedList
<
i32
>
{
list_from
(
&
[
0
,
1
,
2
,
3
,
4
,
5
,
6
])
list_from
(
&
[
0
,
1
,
2
,
3
,
4
,
5
,
6
])
}
#[cfg(test)]
...
...
@@ -78,7 +78,7 @@ fn test_split_off() {
// not singleton, forwards
{
let
u
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
u
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
mut
m
=
list_from
(
&
u
);
let
mut
n
=
m
.split_off
(
2
);
assert_eq!
(
m
.len
(),
2
);
...
...
@@ -92,7 +92,7 @@ fn test_split_off() {
}
// not singleton, backwards
{
let
u
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
u
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
mut
m
=
list_from
(
&
u
);
let
mut
n
=
m
.split_off
(
4
);
assert_eq!
(
m
.len
(),
4
);
...
...
@@ -246,33 +246,33 @@ fn test_eq() {
m
.push_back
(
1
);
assert
!
(
n
==
m
);
let
n
=
list_from
(
&
[
2
,
3
,
4
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
let
n
=
list_from
(
&
[
2
,
3
,
4
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
assert
!
(
n
!=
m
);
}
#[test]
fn
test_hash
()
{
let
mut
x
=
LinkedList
::
new
();
let
mut
y
=
LinkedList
::
new
();
let
mut
x
=
LinkedList
::
new
();
let
mut
y
=
LinkedList
::
new
();
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
3
);
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
3
);
y
.push_front
(
3
);
y
.push_front
(
2
);
y
.push_front
(
1
);
y
.push_front
(
3
);
y
.push_front
(
2
);
y
.push_front
(
1
);
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
}
#[test]
fn
test_ord
()
{
let
n
=
list_from
(
&
[]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
assert
!
(
n
<
m
);
assert
!
(
m
>
n
);
assert
!
(
n
<=
n
);
...
...
@@ -281,7 +281,7 @@ fn test_ord() {
#[test]
fn
test_ord_nan
()
{
let
nan
=
0.0f64
/
0.0
;
let
nan
=
0.0f64
/
0.0
;
let
n
=
list_from
(
&
[
nan
]);
let
m
=
list_from
(
&
[
nan
]);
assert
!
(
!
(
n
<
m
));
...
...
@@ -296,15 +296,15 @@ fn test_ord_nan() {
assert
!
(
!
(
n
<=
one
));
assert
!
(
!
(
n
>=
one
));
let
u
=
list_from
(
&
[
1.0f64
,
2.0
,
nan
]);
let
v
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
]);
let
u
=
list_from
(
&
[
1.0f64
,
2.0
,
nan
]);
let
v
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
]);
assert
!
(
!
(
u
<
v
));
assert
!
(
!
(
u
>
v
));
assert
!
(
!
(
u
<=
v
));
assert
!
(
!
(
u
>=
v
));
let
s
=
list_from
(
&
[
1.0f64
,
2.0
,
4.0
,
2.0
]);
let
t
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
,
2.0
]);
let
s
=
list_from
(
&
[
1.0f64
,
2.0
,
4.0
,
2.0
]);
let
t
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
,
2.0
]);
assert
!
(
!
(
s
<
t
));
assert
!
(
s
>
one
);
assert
!
(
!
(
s
<=
one
));
...
...
@@ -317,7 +317,8 @@ fn test_show() {
assert_eq!
(
format!
(
"{:?}"
,
list
),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
);
let
list
:
LinkedList
<
_
>
=
vec!
[
"just"
,
"one"
,
"test"
,
"more"
]
.iter
()
.cloned
()
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
list
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
assert_eq!
(
format!
(
"{:?}"
,
list
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
}
#[test]
...
...
src/libcollectionstest/slice.rs
浏览文件 @
3d9d96b6
此差异已折叠。
点击以展开。
src/libcollectionstest/string.rs
浏览文件 @
3d9d96b6
...
...
@@ -31,8 +31,8 @@ fn into_cow(self) -> Cow<'a, str> {
#[test]
fn
test_from_str
()
{
let
owned
:
Option
<
::
std
::
string
::
String
>
=
"string"
.parse
()
.ok
();
assert_eq!
(
owned
.as_ref
()
.map
(|
s
|
&**
s
),
Some
(
"string"
));
let
owned
:
Option
<
::
std
::
string
::
String
>
=
"string"
.parse
()
.ok
();
assert_eq!
(
owned
.as_ref
()
.map
(|
s
|
&**
s
),
Some
(
"string"
));
}
#[test]
...
...
@@ -44,8 +44,7 @@ fn test_unsized_to_string() {
#[test]
fn
test_from_utf8
()
{
let
xs
=
b
"hello"
.to_vec
();
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
String
::
from
(
"hello"
));
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
String
::
from
(
"hello"
));
let
xs
=
"ศไทย中华Việt Nam"
.as_bytes
()
.to_vec
();
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
...
...
@@ -87,56 +86,40 @@ fn test_from_utf8_lossy() {
String
::
from
(
"
\
u{FFFD}foo
\
u{FFFD}bar
\
u{FFFD}
\
u{FFFD}baz"
)
.into_cow
());
let
xs
=
b
"
\xF0\x80\x80\x80
foo
\xF0\x90\x80\x80
bar"
;
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
\
foo
\
u{10000}bar"
)
.into_cow
());
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
foo
\
u{10000}bar"
)
.into_cow
());
// surrogates
let
xs
=
b
"
\xED\xA0\x80
foo
\xED\xBF\xBF
bar"
;
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}foo
\
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}bar"
)
.into_cow
());
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}foo
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}bar"
)
.into_cow
());
}
#[test]
fn
test_from_utf16
()
{
let
pairs
=
[(
String
::
from
(
"𐍅𐌿𐌻𐍆𐌹𐌻𐌰
\n
"
),
vec!
[
0xd800
,
0xdf45
,
0xd800
,
0xdf3f
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf46
,
0xd800
,
0xdf39
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf30
,
0x000a
]),
(
String
::
from
(
"𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍
\n
"
),
vec!
[
0xd801
,
0xdc12
,
0xd801
,
0xdc49
,
0xd801
,
0xdc2e
,
0xd801
,
0xdc40
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4b
,
0x0020
,
0xd801
,
0xdc0f
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4d
,
0x000a
]),
(
String
::
from
(
"𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑
\n
"
),
vec!
[
0xd800
,
0xdf00
,
0xd800
,
0xdf16
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf04
,
0xd800
,
0xdf11
,
0xd800
,
0xdf09
,
0x00b7
,
0xd800
,
0xdf0c
,
0xd800
,
0xdf04
,
0xd800
,
0xdf15
,
0xd800
,
0xdf04
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf09
,
0xd800
,
0xdf11
,
0x000a
]),
(
String
::
from
(
"𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆
\n
"
),
vec!
[
0xd801
,
0xdc8b
,
0xd801
,
0xdc98
,
0xd801
,
0xdc88
,
0xd801
,
0xdc91
,
0xd801
,
0xdc9b
,
0xd801
,
0xdc92
,
0x0020
,
0xd801
,
0xdc95
,
0xd801
,
0xdc93
,
0x0020
,
0xd801
,
0xdc88
,
0xd801
,
0xdc9a
,
0xd801
,
0xdc8d
,
0x0020
,
0xd801
,
0xdc8f
,
0xd801
,
0xdc9c
,
0xd801
,
0xdc92
,
0xd801
,
0xdc96
,
0xd801
,
0xdc86
,
0x0020
,
0xd801
,
0xdc95
,
0xd801
,
0xdc86
,
0x000a
]),
// Issue #12318, even-numbered non-BMP planes
(
String
::
from
(
"
\
u{20000}"
),
vec!
[
0xD840
,
0xDC00
])];
let
pairs
=
[(
String
::
from
(
"𐍅𐌿𐌻𐍆𐌹𐌻𐌰
\n
"
),
vec!
[
0xd800
,
0xdf45
,
0xd800
,
0xdf3f
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf46
,
0xd800
,
0xdf39
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf30
,
0x000a
]),
(
String
::
from
(
"𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍
\n
"
),
vec!
[
0xd801
,
0xdc12
,
0xd801
,
0xdc49
,
0xd801
,
0xdc2e
,
0xd801
,
0xdc40
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4b
,
0x0020
,
0xd801
,
0xdc0f
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4d
,
0x000a
]),
(
String
::
from
(
"𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑
\n
"
),
vec!
[
0xd800
,
0xdf00
,
0xd800
,
0xdf16
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf04
,
0xd800
,
0xdf11
,
0xd800
,
0xdf09
,
0x00b7
,
0xd800
,
0xdf0c
,
0xd800
,
0xdf04
,
0xd800
,
0xdf15
,
0xd800
,
0xdf04
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf09
,
0xd800
,
0xdf11
,
0x000a
]),
(
String
::
from
(
"𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆
\n
"
),
vec!
[
0xd801
,
0xdc8b
,
0xd801
,
0xdc98
,
0xd801
,
0xdc88
,
0xd801
,
0xdc91
,
0xd801
,
0xdc9b
,
0xd801
,
0xdc92
,
0x0020
,
0xd801
,
0xdc95
,
0xd801
,
0xdc93
,
0x0020
,
0xd801
,
0xdc88
,
0xd801
,
0xdc9a
,
0xd801
,
0xdc8d
,
0x0020
,
0xd801
,
0xdc8f
,
0xd801
,
0xdc9c
,
0xd801
,
0xdc92
,
0xd801
,
0xdc96
,
0xd801
,
0xdc86
,
0x0020
,
0xd801
,
0xdc95
,
0xd801
,
0xdc86
,
0x000a
]),
// Issue #12318, even-numbered non-BMP planes
(
String
::
from
(
"
\
u{20000}"
),
vec!
[
0xD840
,
0xDC00
])];
for
p
in
&
pairs
{
let
(
s
,
u
)
=
(
*
p
)
.clone
();
...
...
@@ -173,13 +156,15 @@ fn test_utf16_invalid() {
fn
test_from_utf16_lossy
()
{
// completely positive cases tested above.
// lead + eof
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
]),
String
::
from
(
"
\
u{FFFD}"
));
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
]),
String
::
from
(
"
\
u{FFFD}"
));
// lead + lead
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xD800
]),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}"
));
// isolated trail
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0x0061
,
0xDC00
]),
String
::
from
(
"a
\
u{FFFD}"
));
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0x0061
,
0xDC00
]),
String
::
from
(
"a
\
u{FFFD}"
));
// general
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xd801
,
0xdc8b
,
0xD800
]),
...
...
@@ -288,7 +273,8 @@ fn remove() {
assert_eq!
(
s
,
"ไทย中华Vit Nam; foobar"
);
}
#[test]
#[should_panic]
#[test]
#[should_panic]
fn
remove_bad
()
{
"ศ"
.to_string
()
.remove
(
1
);
}
...
...
@@ -302,8 +288,16 @@ fn insert() {
assert_eq!
(
s
,
"ệfooยbar"
);
}
#[test]
#[should_panic]
fn
insert_bad1
()
{
""
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[should_panic]
fn
insert_bad2
()
{
"ệ"
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[should_panic]
fn
insert_bad1
()
{
""
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[should_panic]
fn
insert_bad2
()
{
"ệ"
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
fn
test_slicing
()
{
...
...
@@ -331,8 +325,7 @@ fn test_vectors() {
assert_eq!
(
format!
(
"{:?}"
,
x
),
"[]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
]),
"[1]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
,
2
,
3
]),
"[1, 2, 3]"
);
assert
!
(
format!
(
"{:?}"
,
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]])
==
"[[], [1], [1, 1]]"
);
assert
!
(
format!
(
"{:?}"
,
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]])
==
"[[], [1], [1, 1]]"
);
}
#[test]
...
...
@@ -390,9 +383,7 @@ fn test_into_boxed_str() {
#[bench]
fn
bench_with_capacity
(
b
:
&
mut
Bencher
)
{
b
.iter
(||
{
String
::
with_capacity
(
100
)
});
b
.iter
(||
String
::
with_capacity
(
100
));
}
#[bench]
...
...
@@ -495,25 +486,19 @@ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
fn
bench_from_str
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
String
::
from
(
s
)
})
b
.iter
(||
String
::
from
(
s
))
}
#[bench]
fn
bench_from
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
String
::
from
(
s
)
})
b
.iter
(||
String
::
from
(
s
))
}
#[bench]
fn
bench_to_string
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
s
.to_string
()
})
b
.iter
(||
s
.to_string
())
}
src/libcollectionstest/vec.rs
浏览文件 @
3d9d96b6
...
...
@@ -15,7 +15,7 @@
use
test
::
Bencher
;
struct
DropCounter
<
'a
>
{
count
:
&
'a
mut
u32
count
:
&
'a
mut
u32
,
}
impl
<
'a
>
Drop
for
DropCounter
<
'a
>
{
...
...
@@ -33,17 +33,17 @@ fn test_small_vec_struct() {
fn
test_double_drop
()
{
struct
TwoVec
<
T
>
{
x
:
Vec
<
T
>
,
y
:
Vec
<
T
>
y
:
Vec
<
T
>
,
}
let
(
mut
count_x
,
mut
count_y
)
=
(
0
,
0
);
{
let
mut
tv
=
TwoVec
{
x
:
Vec
::
new
(),
y
:
Vec
::
new
()
y
:
Vec
::
new
()
,
};
tv
.x
.push
(
DropCounter
{
count
:
&
mut
count_x
});
tv
.y
.push
(
DropCounter
{
count
:
&
mut
count_y
});
tv
.x
.push
(
DropCounter
{
count
:
&
mut
count_x
});
tv
.y
.push
(
DropCounter
{
count
:
&
mut
count_y
});
// If Vec had a drop flag, here is where it would be zeroed.
// Instead, it should rely on its internal state to prevent
...
...
@@ -85,12 +85,16 @@ fn test_extend() {
let
mut
w
=
Vec
::
new
();
v
.extend
(
0
..
3
);
for
i
in
0
..
3
{
w
.push
(
i
)
}
for
i
in
0
..
3
{
w
.push
(
i
)
}
assert_eq!
(
v
,
w
);
v
.extend
(
3
..
10
);
for
i
in
3
..
10
{
w
.push
(
i
)
}
for
i
in
3
..
10
{
w
.push
(
i
)
}
assert_eq!
(
v
,
w
);
...
...
@@ -117,7 +121,7 @@ fn test_extend_ref() {
fn
test_slice_from_mut
()
{
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
{
let
slice
=
&
mut
values
[
2
..
];
let
slice
=
&
mut
values
[
2
..
];
assert
!
(
slice
==
[
3
,
4
,
5
]);
for
p
in
slice
{
*
p
+=
2
;
...
...
@@ -131,7 +135,7 @@ fn test_slice_from_mut() {
fn
test_slice_to_mut
()
{
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
{
let
slice
=
&
mut
values
[
..
2
];
let
slice
=
&
mut
values
[
..
2
];
assert
!
(
slice
==
[
1
,
2
]);
for
p
in
slice
{
*
p
+=
1
;
...
...
@@ -169,7 +173,7 @@ fn test_split_at_mut() {
#[test]
fn
test_clone
()
{
let
v
:
Vec
<
i32
>
=
vec!
[];
let
w
=
vec!
(
1
,
2
,
3
)
;
let
w
=
vec!
[
1
,
2
,
3
]
;
assert_eq!
(
v
,
v
.clone
());
...
...
@@ -181,9 +185,9 @@ fn test_clone() {
#[test]
fn
test_clone_from
()
{
let
mut
v
=
vec!
()
;
let
three
:
Vec
<
Box
<
_
>>
=
vec!
(
box
1
,
box
2
,
box
3
)
;
let
two
:
Vec
<
Box
<
_
>>
=
vec!
(
box
4
,
box
5
)
;
let
mut
v
=
vec!
[]
;
let
three
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
]
;
let
two
:
Vec
<
Box
<
_
>>
=
vec!
[
box
4
,
box
5
]
;
// zero, long
v
.clone_from
(
&
three
);
assert_eq!
(
v
,
three
);
...
...
@@ -235,16 +239,22 @@ fn zero_sized_values() {
assert_eq!
(
v
.iter_mut
()
.count
(),
4
);
for
&
mut
()
in
&
mut
v
{}
unsafe
{
v
.set_len
(
0
);
}
unsafe
{
v
.set_len
(
0
);
}
assert_eq!
(
v
.iter_mut
()
.count
(),
0
);
}
#[test]
fn
test_partition
()
{
assert_eq!
(
vec!
[]
.into_iter
()
.partition
(|
x
:
&
i32
|
*
x
<
3
),
(
vec!
[],
vec!
[]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
4
),
(
vec!
[
1
,
2
,
3
],
vec!
[]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
2
),
(
vec!
[
1
],
vec!
[
2
,
3
]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
0
),
(
vec!
[],
vec!
[
1
,
2
,
3
]));
assert_eq!
(
vec!
[]
.into_iter
()
.partition
(|
x
:
&
i32
|
*
x
<
3
),
(
vec!
[],
vec!
[]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
4
),
(
vec!
[
1
,
2
,
3
],
vec!
[]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
2
),
(
vec!
[
1
],
vec!
[
2
,
3
]));
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
0
),
(
vec!
[],
vec!
[
1
,
2
,
3
]));
}
#[test]
...
...
@@ -264,7 +274,9 @@ fn test_vec_truncate_drop() {
struct
Elem
(
i32
);
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
...
...
@@ -344,7 +356,7 @@ fn test_slice_out_of_bounds_5() {
#[test]
#[should_panic]
fn
test_swap_remove_empty
()
{
let
mut
vec
=
Vec
::
<
i32
>
::
new
();
let
mut
vec
=
Vec
::
<
i32
>
::
new
();
vec
.swap_remove
(
0
);
}
...
...
@@ -386,7 +398,7 @@ fn test_drain_items() {
vec2
.push
(
i
);
}
assert_eq!
(
vec
,
[]);
assert_eq!
(
vec2
,
[
1
,
2
,
3
]);
assert_eq!
(
vec2
,
[
1
,
2
,
3
]);
}
#[test]
...
...
@@ -472,7 +484,7 @@ fn test_into_iter_count() {
#[test]
fn
test_into_iter_clone
()
{
fn
iter_equal
<
I
:
Iterator
<
Item
=
i32
>>
(
it
:
I
,
slice
:
&
[
i32
])
{
fn
iter_equal
<
I
:
Iterator
<
Item
=
i32
>>
(
it
:
I
,
slice
:
&
[
i32
])
{
let
v
:
Vec
<
i32
>
=
it
.collect
();
assert_eq!
(
&
v
[
..
],
slice
);
}
...
...
src/libcollectionstest/vec_deque.rs
浏览文件 @
3d9d96b6
...
...
@@ -52,7 +52,7 @@ fn test_simple() {
}
#[cfg(test)]
fn
test_parameterized
<
T
:
Clone
+
PartialEq
+
Debug
>
(
a
:
T
,
b
:
T
,
c
:
T
,
d
:
T
)
{
fn
test_parameterized
<
T
:
Clone
+
PartialEq
+
Debug
>
(
a
:
T
,
b
:
T
,
c
:
T
,
d
:
T
)
{
let
mut
deq
=
VecDeque
::
new
();
assert_eq!
(
deq
.len
(),
0
);
deq
.push_front
(
a
.clone
());
...
...
@@ -186,7 +186,7 @@ enum Taggypar<T> {
struct
RecCy
{
x
:
i32
,
y
:
i32
,
t
:
Taggy
t
:
Taggy
,
}
#[test]
...
...
@@ -209,10 +209,26 @@ fn test_param_taggypar() {
#[test]
fn
test_param_reccy
()
{
let
reccy1
=
RecCy
{
x
:
1
,
y
:
2
,
t
:
One
(
1
)
};
let
reccy2
=
RecCy
{
x
:
345
,
y
:
2
,
t
:
Two
(
1
,
2
)
};
let
reccy3
=
RecCy
{
x
:
1
,
y
:
777
,
t
:
Three
(
1
,
2
,
3
)
};
let
reccy4
=
RecCy
{
x
:
19
,
y
:
252
,
t
:
Two
(
17
,
42
)
};
let
reccy1
=
RecCy
{
x
:
1
,
y
:
2
,
t
:
One
(
1
),
};
let
reccy2
=
RecCy
{
x
:
345
,
y
:
2
,
t
:
Two
(
1
,
2
),
};
let
reccy3
=
RecCy
{
x
:
1
,
y
:
777
,
t
:
Three
(
1
,
2
,
3
),
};
let
reccy4
=
RecCy
{
x
:
19
,
y
:
252
,
t
:
Two
(
17
,
42
),
};
test_parameterized
::
<
RecCy
>
(
reccy1
,
reccy2
,
reccy3
,
reccy4
);
}
...
...
@@ -257,13 +273,13 @@ fn test_with_capacity_non_power_two() {
// underlying Vec which didn't hold and lead
// to corruption.
// (Vec grows to next power of two)
//good- [9, 12, 15, X, X, X, X, |6]
//bug- [15, 12, X, X, X, |6, X, X]
//
good- [9, 12, 15, X, X, X, X, |6]
//
bug- [15, 12, X, X, X, |6, X, X]
assert_eq!
(
d3
.pop_front
(),
Some
(
6
));
// Which leads us to the following state which
// would be a failure case.
//bug- [15, 12, X, X, X, X, |X, X]
//
bug- [15, 12, X, X, X, X, |X, X]
assert_eq!
(
d3
.front
(),
Some
(
&
9
));
}
...
...
@@ -301,7 +317,7 @@ fn test_iter() {
d
.push_back
(
i
);
}
{
let
b
:
&
[
_
]
=
&
[
&
0
,
&
1
,
&
2
,
&
3
,
&
4
];
let
b
:
&
[
_
]
=
&
[
&
0
,
&
1
,
&
2
,
&
3
,
&
4
];
assert_eq!
(
d
.iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
...
...
@@ -309,7 +325,7 @@ fn test_iter() {
d
.push_front
(
i
);
}
{
let
b
:
&
[
_
]
=
&
[
&
8
,
&
7
,
&
6
,
&
0
,
&
1
,
&
2
,
&
3
,
&
4
];
let
b
:
&
[
_
]
=
&
[
&
8
,
&
7
,
&
6
,
&
0
,
&
1
,
&
2
,
&
3
,
&
4
];
assert_eq!
(
d
.iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
...
...
@@ -318,7 +334,10 @@ fn test_iter() {
loop
{
match
it
.next
()
{
None
=>
break
,
_
=>
{
len
-=
1
;
assert_eq!
(
it
.size_hint
(),
(
len
,
Some
(
len
)))
}
_
=>
{
len
-=
1
;
assert_eq!
(
it
.size_hint
(),
(
len
,
Some
(
len
)))
}
}
}
}
...
...
@@ -332,14 +351,14 @@ fn test_rev_iter() {
d
.push_back
(
i
);
}
{
let
b
:
&
[
_
]
=
&
[
&
4
,
&
3
,
&
2
,
&
1
,
&
0
];
let
b
:
&
[
_
]
=
&
[
&
4
,
&
3
,
&
2
,
&
1
,
&
0
];
assert_eq!
(
d
.iter
()
.rev
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
for
i
in
6
..
9
{
d
.push_front
(
i
);
}
let
b
:
&
[
_
]
=
&
[
&
4
,
&
3
,
&
2
,
&
1
,
&
0
,
&
6
,
&
7
,
&
8
];
let
b
:
&
[
_
]
=
&
[
&
4
,
&
3
,
&
2
,
&
1
,
&
0
,
&
6
,
&
7
,
&
8
];
assert_eq!
(
d
.iter
()
.rev
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
...
...
@@ -424,7 +443,7 @@ fn test_into_iter() {
d
.push_back
(
i
);
}
let
b
=
vec!
[
0
,
1
,
2
,
3
,
4
];
let
b
=
vec!
[
0
,
1
,
2
,
3
,
4
];
assert_eq!
(
d
.into_iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
...
...
@@ -438,7 +457,7 @@ fn test_into_iter() {
d
.push_front
(
i
);
}
let
b
=
vec!
[
8
,
7
,
6
,
0
,
1
,
2
,
3
,
4
];
let
b
=
vec!
[
8
,
7
,
6
,
0
,
1
,
2
,
3
,
4
];
assert_eq!
(
d
.into_iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
...
...
@@ -502,7 +521,7 @@ fn test_drain() {
d
.push_front
(
i
);
}
assert_eq!
(
d
.drain
(
..
)
.collect
::
<
Vec
<
_
>>
(),
[
8
,
7
,
6
,
0
,
1
,
2
,
3
,
4
]);
assert_eq!
(
d
.drain
(
..
)
.collect
::
<
Vec
<
_
>>
(),
[
8
,
7
,
6
,
0
,
1
,
2
,
3
,
4
]);
assert
!
(
d
.is_empty
());
}
...
...
@@ -532,7 +551,7 @@ fn test_drain() {
#[test]
fn
test_from_iter
()
{
let
v
=
vec!
(
1
,
2
,
3
,
4
,
5
,
6
,
7
)
;
let
v
=
vec!
[
1
,
2
,
3
,
4
,
5
,
6
,
7
]
;
let
deq
:
VecDeque
<
_
>
=
v
.iter
()
.cloned
()
.collect
();
let
u
:
Vec
<
_
>
=
deq
.iter
()
.cloned
()
.collect
();
assert_eq!
(
u
,
v
);
...
...
@@ -540,7 +559,7 @@ fn test_from_iter() {
let
seq
=
(
0
..
)
.step_by
(
2
)
.take
(
256
);
let
deq
:
VecDeque
<
_
>
=
seq
.collect
();
for
(
i
,
&
x
)
in
deq
.iter
()
.enumerate
()
{
assert_eq!
(
2
*
i
,
x
);
assert_eq!
(
2
*
i
,
x
);
}
assert_eq!
(
deq
.len
(),
256
);
}
...
...
@@ -585,20 +604,20 @@ fn test_eq() {
#[test]
fn
test_hash
()
{
let
mut
x
=
VecDeque
::
new
();
let
mut
y
=
VecDeque
::
new
();
let
mut
x
=
VecDeque
::
new
();
let
mut
y
=
VecDeque
::
new
();
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
3
);
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
3
);
y
.push_back
(
0
);
y
.push_back
(
1
);
y
.pop_front
();
y
.push_back
(
2
);
y
.push_back
(
3
);
y
.push_back
(
0
);
y
.push_back
(
1
);
y
.pop_front
();
y
.push_back
(
2
);
y
.push_back
(
3
);
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
}
#[test]
...
...
@@ -665,10 +684,12 @@ fn test_show() {
let
ringbuf
:
VecDeque
<
_
>
=
(
0
..
10
)
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
);
let
ringbuf
:
VecDeque
<
_
>
=
vec!
[
"just"
,
"one"
,
"test"
,
"more"
]
.iter
()
.cloned
()
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
let
ringbuf
:
VecDeque
<
_
>
=
vec!
[
"just"
,
"one"
,
"test"
,
"more"
]
.iter
()
.cloned
()
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
}
#[test]
...
...
@@ -677,7 +698,9 @@ fn test_drop() {
struct
Elem
;
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
...
...
@@ -688,7 +711,7 @@ fn drop(&mut self) {
ring
.push_front
(
Elem
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
#[test]
...
...
@@ -697,7 +720,9 @@ fn test_drop_with_pop() {
struct
Elem
;
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
...
...
@@ -709,10 +734,10 @@ fn drop(&mut self) {
drop
(
ring
.pop_back
());
drop
(
ring
.pop_front
());
assert_eq!
(
unsafe
{
drops
},
2
);
assert_eq!
(
unsafe
{
drops
},
2
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
#[test]
...
...
@@ -721,7 +746,9 @@ fn test_drop_clear() {
struct
Elem
;
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
...
...
@@ -731,10 +758,10 @@ fn drop(&mut self) {
ring
.push_back
(
Elem
);
ring
.push_front
(
Elem
);
ring
.clear
();
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
#[test]
...
...
@@ -822,7 +849,7 @@ fn test_get_mut() {
match
ring
.get_mut
(
1
)
{
Some
(
x
)
=>
*
x
=
-
1
,
None
=>
()
None
=>
()
,
};
assert_eq!
(
ring
.get_mut
(
0
),
Some
(
&
mut
0
));
...
...
@@ -852,13 +879,13 @@ fn test_front() {
fn
test_as_slices
()
{
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
cap
=
ring
.capacity
()
as
i32
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
for
i
in
0
..
first
{
ring
.push_back
(
i
);
let
(
left
,
right
)
=
ring
.as_slices
();
let
expected
:
Vec
<
_
>
=
(
0
..
i
+
1
)
.collect
();
let
expected
:
Vec
<
_
>
=
(
0
..
i
+
1
)
.collect
();
assert_eq!
(
left
,
&
expected
[
..
]);
assert_eq!
(
right
,
[]);
}
...
...
@@ -866,7 +893,7 @@ fn test_as_slices() {
for
j
in
-
last
..
0
{
ring
.push_front
(
j
);
let
(
left
,
right
)
=
ring
.as_slices
();
let
expected_left
:
Vec
<
_
>
=
(
-
last
..
j
+
1
)
.rev
()
.collect
();
let
expected_left
:
Vec
<
_
>
=
(
-
last
..
j
+
1
)
.rev
()
.collect
();
let
expected_right
:
Vec
<
_
>
=
(
0
..
first
)
.collect
();
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
...
...
@@ -880,13 +907,13 @@ fn test_as_slices() {
fn
test_as_mut_slices
()
{
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
cap
=
ring
.capacity
()
as
i32
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
for
i
in
0
..
first
{
ring
.push_back
(
i
);
let
(
left
,
right
)
=
ring
.as_mut_slices
();
let
expected
:
Vec
<
_
>
=
(
0
..
i
+
1
)
.collect
();
let
expected
:
Vec
<
_
>
=
(
0
..
i
+
1
)
.collect
();
assert_eq!
(
left
,
&
expected
[
..
]);
assert_eq!
(
right
,
[]);
}
...
...
@@ -894,7 +921,7 @@ fn test_as_mut_slices() {
for
j
in
-
last
..
0
{
ring
.push_front
(
j
);
let
(
left
,
right
)
=
ring
.as_mut_slices
();
let
expected_left
:
Vec
<
_
>
=
(
-
last
..
j
+
1
)
.rev
()
.collect
();
let
expected_left
:
Vec
<
_
>
=
(
-
last
..
j
+
1
)
.rev
()
.collect
();
let
expected_right
:
Vec
<
_
>
=
(
0
..
first
)
.collect
();
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录