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 @@
...
@@ -9,7 +9,7 @@
// except according to those terms.
// except according to those terms.
use
std
::
collections
::
BTreeMap
;
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
::
collections
::
btree_map
::
Entry
::{
Occupied
,
Vacant
};
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
...
@@ -20,41 +20,41 @@ fn test_basic_large() {
...
@@ -20,41 +20,41 @@ fn test_basic_large() {
assert_eq!
(
map
.len
(),
0
);
assert_eq!
(
map
.len
(),
0
);
for
i
in
0
..
size
{
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
.len
(),
i
+
1
);
}
}
for
i
in
0
..
size
{
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
);
assert_eq!
(
map
.get
(
&
i
),
None
);
}
}
for
i
in
0
..
size
{
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
.len
(),
size
);
}
}
for
i
in
0
..
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
{
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
}
}
for
i
in
0
..
size
/
2
{
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.get
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.get
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.get
(
&
(
2
*
i
+
1
))
.unwrap
(),
&
(
i
*
200
+
100
));
assert_eq!
(
map
.get
(
&
(
2
*
i
+
1
))
.unwrap
(),
&
(
i
*
200
+
100
));
}
}
for
i
in
0
..
size
/
2
{
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
}
}
}
}
...
@@ -81,7 +81,9 @@ fn test_iter() {
...
@@ -81,7 +81,9 @@ fn test_iter() {
// Forwards
// Forwards
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
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
{
for
i
in
0
..
size
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
...
@@ -101,7 +103,9 @@ fn test_iter_rev() {
...
@@ -101,7 +103,9 @@ fn test_iter_rev() {
// Forwards
// Forwards
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
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
{
for
i
in
0
..
size
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
,
Some
(
size
-
i
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
size
-
i
-
1
,
size
-
i
-
1
));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
size
-
i
-
1
,
size
-
i
-
1
));
...
@@ -125,8 +129,7 @@ fn test_values_mut() {
...
@@ -125,8 +129,7 @@ fn test_values_mut() {
}
}
let
values
:
Vec
<
String
>
=
a
.values
()
.cloned
()
.collect
();
let
values
:
Vec
<
String
>
=
a
.values
()
.cloned
()
.collect
();
assert_eq!
(
values
,
[
String
::
from
(
"hello!"
),
assert_eq!
(
values
,
[
String
::
from
(
"hello!"
),
String
::
from
(
"goodbye!"
)]);
String
::
from
(
"goodbye!"
)]);
}
}
#[test]
#[test]
...
@@ -137,7 +140,8 @@ fn test_iter_mixed() {
...
@@ -137,7 +140,8 @@ fn test_iter_mixed() {
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
let
mut
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
fn
test
<
T
>
(
size
:
usize
,
mut
iter
:
T
)
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
{
for
i
in
0
..
size
/
4
{
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
*
2
,
Some
(
size
-
i
*
2
)));
assert_eq!
(
iter
.size_hint
(),
(
size
-
i
*
2
,
Some
(
size
-
i
*
2
)));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
assert_eq!
(
iter
.next
()
.unwrap
(),
(
i
,
i
));
...
@@ -202,7 +206,7 @@ fn test_range() {
...
@@ -202,7 +206,7 @@ fn test_range() {
for
i
in
0
..
size
{
for
i
in
0
..
size
{
for
j
in
i
..
size
{
for
j
in
i
..
size
{
let
mut
kvs
=
map
.range
(
Included
(
&
i
),
Included
(
&
j
))
.map
(|(
&
k
,
&
v
)|
(
k
,
v
));
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
())
{
for
(
kv
,
pair
)
in
kvs
.by_ref
()
.zip
(
pairs
.by_ref
())
{
assert_eq!
(
kv
,
pair
);
assert_eq!
(
kv
,
pair
);
...
@@ -242,7 +246,7 @@ fn test_borrow() {
...
@@ -242,7 +246,7 @@ fn test_borrow() {
}
}
#[test]
#[test]
fn
test_entry
(){
fn
test_entry
()
{
let
xs
=
[(
1
,
10
),
(
2
,
20
),
(
3
,
30
),
(
4
,
40
),
(
5
,
50
),
(
6
,
60
)];
let
xs
=
[(
1
,
10
),
(
2
,
20
),
(
3
,
30
),
(
4
,
40
),
(
5
,
50
),
(
6
,
60
)];
let
mut
map
:
BTreeMap
<
_
,
_
>
=
xs
.iter
()
.cloned
()
.collect
();
let
mut
map
:
BTreeMap
<
_
,
_
>
=
xs
.iter
()
.cloned
()
.collect
();
...
@@ -341,17 +345,23 @@ fn test_bad_zst() {
...
@@ -341,17 +345,23 @@ fn test_bad_zst() {
struct
Bad
;
struct
Bad
;
impl
PartialEq
for
Bad
{
impl
PartialEq
for
Bad
{
fn
eq
(
&
self
,
_
:
&
Self
)
->
bool
{
false
}
fn
eq
(
&
self
,
_
:
&
Self
)
->
bool
{
false
}
}
}
impl
Eq
for
Bad
{}
impl
Eq
for
Bad
{}
impl
PartialOrd
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
{
impl
Ord
for
Bad
{
fn
cmp
(
&
self
,
_
:
&
Self
)
->
Ordering
{
Ordering
::
Less
}
fn
cmp
(
&
self
,
_
:
&
Self
)
->
Ordering
{
Ordering
::
Less
}
}
}
let
mut
m
=
BTreeMap
::
new
();
let
mut
m
=
BTreeMap
::
new
();
...
@@ -368,27 +378,27 @@ fn test_clone() {
...
@@ -368,27 +378,27 @@ fn test_clone() {
assert_eq!
(
map
.len
(),
0
);
assert_eq!
(
map
.len
(),
0
);
for
i
in
0
..
size
{
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
.len
(),
i
+
1
);
assert_eq!
(
map
,
map
.clone
());
assert_eq!
(
map
,
map
.clone
());
}
}
for
i
in
0
..
size
{
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
.len
(),
size
);
assert_eq!
(
map
,
map
.clone
());
assert_eq!
(
map
,
map
.clone
());
}
}
for
i
in
0
..
size
/
2
{
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.remove
(
&
(
i
*
2
)),
Some
(
i
*
200
));
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
assert_eq!
(
map
.len
(),
size
-
i
-
1
);
assert_eq!
(
map
,
map
.clone
());
assert_eq!
(
map
,
map
.clone
());
}
}
for
i
in
0
..
size
/
2
{
for
i
in
0
..
size
/
2
{
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
)),
None
);
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.remove
(
&
(
2
*
i
+
1
)),
Some
(
i
*
200
+
100
));
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
assert_eq!
(
map
.len
(),
size
/
2
-
i
-
1
);
assert_eq!
(
map
,
map
.clone
());
assert_eq!
(
map
,
map
.clone
());
}
}
}
}
...
@@ -398,16 +408,36 @@ fn test_clone() {
...
@@ -398,16 +408,36 @@ fn test_clone() {
fn
test_variance
()
{
fn
test_variance
()
{
use
std
::
collections
::
btree_map
::{
Iter
,
IntoIter
,
Range
,
Keys
,
Values
};
use
std
::
collections
::
btree_map
::{
Iter
,
IntoIter
,
Range
,
Keys
,
Values
};
fn
map_key
<
'new
>
(
v
:
BTreeMap
<&
'static
str
,
()
>
)
->
BTreeMap
<&
'new
str
,
()
>
{
v
}
fn
map_key
<
'new
>
(
v
:
BTreeMap
<&
'static
str
,
()
>
)
->
BTreeMap
<&
'new
str
,
()
>
{
fn
map_val
<
'new
>
(
v
:
BTreeMap
<
(),
&
'static
str
>
)
->
BTreeMap
<
(),
&
'new
str
>
{
v
}
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
map_val
<
'new
>
(
v
:
BTreeMap
<
(),
&
'static
str
>
)
->
BTreeMap
<
(),
&
'new
str
>
{
fn
into_iter_key
<
'new
>
(
v
:
IntoIter
<&
'static
str
,
()
>
)
->
IntoIter
<&
'new
str
,
()
>
{
v
}
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
iter_key
<
'a
,
'new
>
(
v
:
Iter
<
'a
,
&
'static
str
,
()
>
)
->
Iter
<
'a
,
&
'new
str
,
()
>
{
fn
range_val
<
'a
,
'new
>
(
v
:
Range
<
'a
,
(),
&
'static
str
>
)
->
Range
<
'a
,
(),
&
'new
str
>
{
v
}
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
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]
#[test]
...
@@ -440,7 +470,7 @@ fn test_vacant_entry_key() {
...
@@ -440,7 +470,7 @@ fn test_vacant_entry_key() {
Vacant
(
e
)
=>
{
Vacant
(
e
)
=>
{
assert_eq!
(
key
,
*
e
.key
());
assert_eq!
(
key
,
*
e
.key
());
e
.insert
(
value
.clone
());
e
.insert
(
value
.clone
());
}
,
}
}
}
assert_eq!
(
a
.len
(),
1
);
assert_eq!
(
a
.len
(),
1
);
assert_eq!
(
a
[
key
],
value
);
assert_eq!
(
a
[
key
],
value
);
...
...
src/libcollectionstest/enum_set.rs
浏览文件 @
3d9d96b6
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
#[derive(Copy,
Clone,
PartialEq,
Debug)]
#[derive(Copy,
Clone,
PartialEq,
Debug)]
#[repr(usize)]
#[repr(usize)]
enum
Foo
{
enum
Foo
{
A
,
B
,
C
A
,
B
,
C
,
}
}
impl
CLike
for
Foo
{
impl
CLike
for
Foo
{
...
@@ -60,9 +62,8 @@ fn test_len() {
...
@@ -60,9 +62,8 @@ fn test_len() {
assert_eq!
(
e
.len
(),
0
);
assert_eq!
(
e
.len
(),
0
);
}
}
///////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
// intersect
/// intersect
#[test]
#[test]
fn
test_two_empties_do_not_intersect
()
{
fn
test_two_empties_do_not_intersect
()
{
let
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
let
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
@@ -105,9 +106,8 @@ fn test_overlapping_intersects() {
...
@@ -105,9 +106,8 @@ fn test_overlapping_intersects() {
assert
!
(
!
e1
.is_disjoint
(
&
e2
));
assert
!
(
!
e1
.is_disjoint
(
&
e2
));
}
}
///////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
// contains and contains_elem
/// contains and contains_elem
#[test]
#[test]
fn
test_superset
()
{
fn
test_superset
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
@@ -141,9 +141,8 @@ fn test_contains() {
...
@@ -141,9 +141,8 @@ fn test_contains() {
assert
!
(
!
e1
.contains
(
&
C
));
assert
!
(
!
e1
.contains
(
&
C
));
}
}
///////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
// iter
/// iter
#[test]
#[test]
fn
test_iterator
()
{
fn
test_iterator
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
@@ -157,20 +156,19 @@ fn test_iterator() {
...
@@ -157,20 +156,19 @@ fn test_iterator() {
e1
.insert
(
C
);
e1
.insert
(
C
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
C
]);
assert_eq!
(
elems
,
[
A
,
C
]);
e1
.insert
(
C
);
e1
.insert
(
C
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
C
]);
assert_eq!
(
elems
,
[
A
,
C
]);
e1
.insert
(
B
);
e1
.insert
(
B
);
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e1
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
assert_eq!
(
elems
,
[
A
,
B
,
C
]);
}
}
///////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
// operators
/// operators
#[test]
#[test]
fn
test_operators
()
{
fn
test_operators
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
new
();
...
@@ -183,7 +181,7 @@ fn test_operators() {
...
@@ -183,7 +181,7 @@ fn test_operators() {
let
e_union
=
e1
|
e2
;
let
e_union
=
e1
|
e2
;
let
elems
:
Vec
<
_
>
=
e_union
.iter
()
.collect
();
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
e_intersection
=
e1
&
e2
;
let
elems
:
Vec
<
_
>
=
e_intersection
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e_intersection
.iter
()
.collect
();
...
@@ -201,17 +199,17 @@ fn test_operators() {
...
@@ -201,17 +199,17 @@ fn test_operators() {
// Bitwise XOR of two sets, aka symmetric difference
// Bitwise XOR of two sets, aka symmetric difference
let
e_symmetric_diff
=
e1
^
e2
;
let
e_symmetric_diff
=
e1
^
e2
;
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
]);
assert_eq!
(
elems
,
[
A
,
B
]);
// Another way to express symmetric difference
// Another way to express symmetric difference
let
e_symmetric_diff
=
(
e1
-
e2
)
|
(
e2
-
e1
);
let
e_symmetric_diff
=
(
e1
-
e2
)
|
(
e2
-
e1
);
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
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
// Yet another way to express symmetric difference
let
e_symmetric_diff
=
(
e1
|
e2
)
-
(
e1
&
e2
);
let
e_symmetric_diff
=
(
e1
|
e2
)
-
(
e1
&
e2
);
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
let
elems
:
Vec
<
_
>
=
e_symmetric_diff
.iter
()
.collect
();
assert_eq!
(
elems
,
[
A
,
B
]);
assert_eq!
(
elems
,
[
A
,
B
]);
}
}
#[test]
#[test]
...
@@ -221,13 +219,76 @@ fn test_overflow() {
...
@@ -221,13 +219,76 @@ fn test_overflow() {
#[derive(Copy,
Clone)]
#[derive(Copy,
Clone)]
#[repr(usize)]
#[repr(usize)]
enum
Bar
{
enum
Bar
{
V00
,
V01
,
V02
,
V03
,
V04
,
V05
,
V06
,
V07
,
V08
,
V09
,
V00
,
V10
,
V11
,
V12
,
V13
,
V14
,
V15
,
V16
,
V17
,
V18
,
V19
,
V01
,
V20
,
V21
,
V22
,
V23
,
V24
,
V25
,
V26
,
V27
,
V28
,
V29
,
V02
,
V30
,
V31
,
V32
,
V33
,
V34
,
V35
,
V36
,
V37
,
V38
,
V39
,
V03
,
V40
,
V41
,
V42
,
V43
,
V44
,
V45
,
V46
,
V47
,
V48
,
V49
,
V04
,
V50
,
V51
,
V52
,
V53
,
V54
,
V55
,
V56
,
V57
,
V58
,
V59
,
V05
,
V60
,
V61
,
V62
,
V63
,
V64
,
V65
,
V66
,
V67
,
V68
,
V69
,
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
{
impl
CLike
for
Bar
{
...
...
src/libcollectionstest/linked_list.rs
浏览文件 @
3d9d96b6
...
@@ -54,7 +54,7 @@ fn test_basic() {
...
@@ -54,7 +54,7 @@ fn test_basic() {
#[cfg(test)]
#[cfg(test)]
fn
generate_test
()
->
LinkedList
<
i32
>
{
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)]
#[cfg(test)]
...
@@ -78,7 +78,7 @@ fn test_split_off() {
...
@@ -78,7 +78,7 @@ fn test_split_off() {
// not singleton, forwards
// 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
m
=
list_from
(
&
u
);
let
mut
n
=
m
.split_off
(
2
);
let
mut
n
=
m
.split_off
(
2
);
assert_eq!
(
m
.len
(),
2
);
assert_eq!
(
m
.len
(),
2
);
...
@@ -92,7 +92,7 @@ fn test_split_off() {
...
@@ -92,7 +92,7 @@ fn test_split_off() {
}
}
// not singleton, backwards
// 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
m
=
list_from
(
&
u
);
let
mut
n
=
m
.split_off
(
4
);
let
mut
n
=
m
.split_off
(
4
);
assert_eq!
(
m
.len
(),
4
);
assert_eq!
(
m
.len
(),
4
);
...
@@ -246,33 +246,33 @@ fn test_eq() {
...
@@ -246,33 +246,33 @@ fn test_eq() {
m
.push_back
(
1
);
m
.push_back
(
1
);
assert
!
(
n
==
m
);
assert
!
(
n
==
m
);
let
n
=
list_from
(
&
[
2
,
3
,
4
]);
let
n
=
list_from
(
&
[
2
,
3
,
4
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
assert
!
(
n
!=
m
);
assert
!
(
n
!=
m
);
}
}
#[test]
#[test]
fn
test_hash
()
{
fn
test_hash
()
{
let
mut
x
=
LinkedList
::
new
();
let
mut
x
=
LinkedList
::
new
();
let
mut
y
=
LinkedList
::
new
();
let
mut
y
=
LinkedList
::
new
();
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
x
.push_back
(
1
);
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
2
);
x
.push_back
(
3
);
x
.push_back
(
3
);
y
.push_front
(
3
);
y
.push_front
(
3
);
y
.push_front
(
2
);
y
.push_front
(
2
);
y
.push_front
(
1
);
y
.push_front
(
1
);
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
}
}
#[test]
#[test]
fn
test_ord
()
{
fn
test_ord
()
{
let
n
=
list_from
(
&
[]);
let
n
=
list_from
(
&
[]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
let
m
=
list_from
(
&
[
1
,
2
,
3
]);
assert
!
(
n
<
m
);
assert
!
(
n
<
m
);
assert
!
(
m
>
n
);
assert
!
(
m
>
n
);
assert
!
(
n
<=
n
);
assert
!
(
n
<=
n
);
...
@@ -281,7 +281,7 @@ fn test_ord() {
...
@@ -281,7 +281,7 @@ fn test_ord() {
#[test]
#[test]
fn
test_ord_nan
()
{
fn
test_ord_nan
()
{
let
nan
=
0.0f64
/
0.0
;
let
nan
=
0.0f64
/
0.0
;
let
n
=
list_from
(
&
[
nan
]);
let
n
=
list_from
(
&
[
nan
]);
let
m
=
list_from
(
&
[
nan
]);
let
m
=
list_from
(
&
[
nan
]);
assert
!
(
!
(
n
<
m
));
assert
!
(
!
(
n
<
m
));
...
@@ -296,15 +296,15 @@ fn test_ord_nan() {
...
@@ -296,15 +296,15 @@ fn test_ord_nan() {
assert
!
(
!
(
n
<=
one
));
assert
!
(
!
(
n
<=
one
));
assert
!
(
!
(
n
>=
one
));
assert
!
(
!
(
n
>=
one
));
let
u
=
list_from
(
&
[
1.0f64
,
2.0
,
nan
]);
let
u
=
list_from
(
&
[
1.0f64
,
2.0
,
nan
]);
let
v
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
]);
let
v
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
]);
assert
!
(
!
(
u
<
v
));
assert
!
(
!
(
u
<
v
));
assert
!
(
!
(
u
>
v
));
assert
!
(
!
(
u
>
v
));
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
s
=
list_from
(
&
[
1.0f64
,
2.0
,
4.0
,
2.0
]);
let
t
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
,
2.0
]);
let
t
=
list_from
(
&
[
1.0f64
,
2.0
,
3.0
,
2.0
]);
assert
!
(
!
(
s
<
t
));
assert
!
(
!
(
s
<
t
));
assert
!
(
s
>
one
);
assert
!
(
s
>
one
);
assert
!
(
!
(
s
<=
one
));
assert
!
(
!
(
s
<=
one
));
...
@@ -317,7 +317,8 @@ fn test_show() {
...
@@ -317,7 +317,8 @@ fn test_show() {
assert_eq!
(
format!
(
"{:?}"
,
list
),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
);
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
();
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]
#[test]
...
...
src/libcollectionstest/slice.rs
浏览文件 @
3d9d96b6
...
@@ -13,9 +13,13 @@
...
@@ -13,9 +13,13 @@
use
std
::
__
rand
::{
Rng
,
thread_rng
};
use
std
::
__
rand
::{
Rng
,
thread_rng
};
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
fn
square
(
n
:
usize
)
->
usize
{
n
*
n
}
fn
square
(
n
:
usize
)
->
usize
{
n
*
n
}
fn
is_odd
(
n
:
&
usize
)
->
bool
{
*
n
%
2
==
1
}
fn
is_odd
(
n
:
&
usize
)
->
bool
{
*
n
%
2
==
1
}
#[test]
#[test]
fn
test_from_fn
()
{
fn
test_from_fn
()
{
...
@@ -76,9 +80,9 @@ fn test_is_empty() {
...
@@ -76,9 +80,9 @@ fn test_is_empty() {
#[test]
#[test]
fn
test_len_divzero
()
{
fn
test_len_divzero
()
{
type
Z
=
[
i8
;
0
];
type
Z
=
[
i8
;
0
];
let
v0
:
&
[
Z
]
=
&
[];
let
v0
:
&
[
Z
]
=
&
[];
let
v1
:
&
[
Z
]
=
&
[[]];
let
v1
:
&
[
Z
]
=
&
[[]];
let
v2
:
&
[
Z
]
=
&
[[],
[]];
let
v2
:
&
[
Z
]
=
&
[[],
[]];
assert_eq!
(
mem
::
size_of
::
<
Z
>
(),
0
);
assert_eq!
(
mem
::
size_of
::
<
Z
>
(),
0
);
assert_eq!
(
v0
.len
(),
0
);
assert_eq!
(
v0
.len
(),
0
);
assert_eq!
(
v1
.len
(),
1
);
assert_eq!
(
v1
.len
(),
1
);
...
@@ -295,7 +299,7 @@ fn test_push() {
...
@@ -295,7 +299,7 @@ fn test_push() {
#[test]
#[test]
fn
test_truncate
()
{
fn
test_truncate
()
{
let
mut
v
:
Vec
<
Box
<
_
>>
=
vec!
[
box
6
,
box
5
,
box
4
];
let
mut
v
:
Vec
<
Box
<
_
>>
=
vec!
[
box
6
,
box
5
,
box
4
];
v
.truncate
(
1
);
v
.truncate
(
1
);
let
v
=
v
;
let
v
=
v
;
assert_eq!
(
v
.len
(),
1
);
assert_eq!
(
v
.len
(),
1
);
...
@@ -305,7 +309,7 @@ fn test_truncate() {
...
@@ -305,7 +309,7 @@ fn test_truncate() {
#[test]
#[test]
fn
test_clear
()
{
fn
test_clear
()
{
let
mut
v
:
Vec
<
Box
<
_
>>
=
vec!
[
box
6
,
box
5
,
box
4
];
let
mut
v
:
Vec
<
Box
<
_
>>
=
vec!
[
box
6
,
box
5
,
box
4
];
v
.clear
();
v
.clear
();
assert_eq!
(
v
.len
(),
0
);
assert_eq!
(
v
.len
(),
0
);
// If the unsafe block didn't drop things properly, we blow up here.
// If the unsafe block didn't drop things properly, we blow up here.
...
@@ -320,12 +324,12 @@ fn case(a: Vec<i32>, b: Vec<i32>) {
...
@@ -320,12 +324,12 @@ fn case(a: Vec<i32>, b: Vec<i32>) {
}
}
case
(
vec!
[],
vec!
[]);
case
(
vec!
[],
vec!
[]);
case
(
vec!
[
1
],
vec!
[
1
]);
case
(
vec!
[
1
],
vec!
[
1
]);
case
(
vec!
[
1
,
1
],
vec!
[
1
]);
case
(
vec!
[
1
,
1
],
vec!
[
1
]);
case
(
vec!
[
1
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
1
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
1
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
2
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
2
,
2
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
2
,
3
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
2
,
3
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
1
,
2
,
2
,
2
,
3
,
3
],
vec!
[
1
,
2
,
3
]);
case
(
vec!
[
1
,
1
,
2
,
2
,
2
,
3
,
3
],
vec!
[
1
,
2
,
3
]);
}
}
#[test]
#[test]
...
@@ -336,10 +340,9 @@ fn test_dedup_unique() {
...
@@ -336,10 +340,9 @@ fn test_dedup_unique() {
v1
.dedup
();
v1
.dedup
();
let
mut
v2
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
,
box
3
];
let
mut
v2
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
,
box
3
];
v2
.dedup
();
v2
.dedup
();
/*
// If the boxed pointers were leaked or otherwise misused, valgrind
* If the boxed pointers were leaked or otherwise misused, valgrind
// and/or rt should raise errors.
* and/or rt should raise errors.
//
*/
}
}
#[test]
#[test]
...
@@ -350,10 +353,9 @@ fn test_dedup_shared() {
...
@@ -350,10 +353,9 @@ fn test_dedup_shared() {
v1
.dedup
();
v1
.dedup
();
let
mut
v2
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
,
box
3
];
let
mut
v2
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
,
box
3
];
v2
.dedup
();
v2
.dedup
();
/*
// If the pointers were leaked or otherwise misused, valgrind and/or
* If the pointers were leaked or otherwise misused, valgrind and/or
// rt should raise errors.
* rt should raise errors.
//
*/
}
}
#[test]
#[test]
...
@@ -365,31 +367,31 @@ fn test_retain() {
...
@@ -365,31 +367,31 @@ fn test_retain() {
#[test]
#[test]
fn
test_binary_search
()
{
fn
test_binary_search
()
{
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
5
)
.ok
(),
Some
(
4
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
5
)
.ok
(),
Some
(
4
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
4
)
.ok
(),
Some
(
3
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
4
)
.ok
(),
Some
(
3
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
3
)
.ok
(),
Some
(
2
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
3
)
.ok
(),
Some
(
2
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
2
)
.ok
(),
Some
(
1
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
2
)
.ok
(),
Some
(
1
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
1
)
.ok
(),
Some
(
0
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
1
)
.ok
(),
Some
(
0
));
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
10
)
.ok
(),
Some
(
4
));
assert_eq!
([
2
,
4
,
6
,
8
,
10
]
.binary_search
(
&
10
)
.ok
(),
Some
(
4
));
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
8
)
.ok
(),
Some
(
3
));
assert_eq!
([
2
,
4
,
6
,
8
]
.binary_search
(
&
8
)
.ok
(),
Some
(
3
));
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
6
)
.ok
(),
Some
(
2
));
assert_eq!
([
2
,
4
,
6
]
.binary_search
(
&
6
)
.ok
(),
Some
(
2
));
assert_eq!
([
2
,
4
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
,
4
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
,
4
]
.binary_search
(
&
2
)
.ok
(),
Some
(
0
));
assert_eq!
([
2
,
4
]
.binary_search
(
&
2
)
.ok
(),
Some
(
0
));
assert_eq!
([
2
,
4
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
,
4
]
.binary_search
(
&
4
)
.ok
(),
Some
(
1
));
assert_eq!
([
2
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([
2
]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([
2
]
.binary_search
(
&
5
)
.ok
(),
None
);
...
@@ -398,14 +400,14 @@ fn test_binary_search() {
...
@@ -398,14 +400,14 @@ fn test_binary_search() {
assert_eq!
([]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([]
.binary_search
(
&
1
)
.ok
(),
None
);
assert_eq!
([]
.binary_search
(
&
5
)
.ok
(),
None
);
assert_eq!
([]
.binary_search
(
&
5
)
.ok
(),
None
);
assert
!
([
1
,
1
,
1
,
1
,
1
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
1
,
1
,
1
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
1
,
1
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
1
,
1
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
1
,
2
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
1
,
2
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
2
,
2
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert
!
([
1
,
1
,
2
,
2
,
2
]
.binary_search
(
&
1
)
.ok
()
!=
None
);
assert_eq!
([
1
,
2
,
2
,
2
,
2
]
.binary_search
(
&
1
)
.ok
(),
Some
(
0
));
assert_eq!
([
1
,
2
,
2
,
2
,
2
]
.binary_search
(
&
1
)
.ok
(),
Some
(
0
));
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
6
)
.ok
(),
None
);
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
6
)
.ok
(),
None
);
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
0
)
.ok
(),
None
);
assert_eq!
([
1
,
2
,
3
,
4
,
5
]
.binary_search
(
&
0
)
.ok
(),
None
);
}
}
#[test]
#[test]
...
@@ -460,15 +462,17 @@ fn test_sort_stability() {
...
@@ -460,15 +462,17 @@ fn test_sort_stability() {
// the second item represents which occurrence of that
// the second item represents which occurrence of that
// number this element is, i.e. the second elements
// number this element is, i.e. the second elements
// will occur in sorted order.
// will occur in sorted order.
let
mut
v
:
Vec
<
_
>
=
(
0
..
len
)
.map
(|
_
|
{
let
mut
v
:
Vec
<
_
>
=
(
0
..
len
)
let
n
=
thread_rng
()
.gen
::
<
usize
>
()
%
10
;
.map
(|
_
|
{
counts
[
n
]
+=
1
;
let
n
=
thread_rng
()
.gen
::
<
usize
>
()
%
10
;
(
n
,
counts
[
n
])
counts
[
n
]
+=
1
;
})
.collect
();
(
n
,
counts
[
n
])
})
.collect
();
// only sort on the first element, so an unstable sort
// only sort on the first element, so an unstable sort
// may mix up the counts.
// may mix up the counts.
v
.sort_by
(|
&
(
a
,
_
),
&
(
b
,
_
)|
a
.cmp
(
&
b
));
v
.sort_by
(|
&
(
a
,
_
),
&
(
b
,
_
)|
a
.cmp
(
&
b
));
// this comparison includes the count (the second item
// this comparison includes the count (the second item
// of the tuple), so elements with equal first items
// of the tuple), so elements with equal first items
...
@@ -679,7 +683,7 @@ fn test_rev_iterator() {
...
@@ -679,7 +683,7 @@ fn test_rev_iterator() {
#[test]
#[test]
fn
test_mut_rev_iterator
()
{
fn
test_mut_rev_iterator
()
{
let
mut
xs
=
[
1
,
2
,
3
,
4
,
5
];
let
mut
xs
=
[
1
,
2
,
3
,
4
,
5
];
for
(
i
,
x
)
in
xs
.iter_mut
()
.rev
()
.enumerate
()
{
for
(
i
,
x
)
in
xs
.iter_mut
()
.rev
()
.enumerate
()
{
*
x
+=
i
;
*
x
+=
i
;
}
}
assert
!
(
xs
==
[
5
,
5
,
5
,
5
,
5
])
assert
!
(
xs
==
[
5
,
5
,
5
,
5
,
5
])
...
@@ -687,35 +691,32 @@ fn test_mut_rev_iterator() {
...
@@ -687,35 +691,32 @@ fn test_mut_rev_iterator() {
#[test]
#[test]
fn
test_move_iterator
()
{
fn
test_move_iterator
()
{
let
xs
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
vec!
[
1
,
2
,
3
,
4
,
5
];
assert_eq!
(
xs
.into_iter
()
.fold
(
0
,
|
a
:
usize
,
b
:
usize
|
10
*
a
+
b
),
12345
);
assert_eq!
(
xs
.into_iter
()
.fold
(
0
,
|
a
:
usize
,
b
:
usize
|
10
*
a
+
b
),
12345
);
}
}
#[test]
#[test]
fn
test_move_rev_iterator
()
{
fn
test_move_rev_iterator
()
{
let
xs
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
vec!
[
1
,
2
,
3
,
4
,
5
];
assert_eq!
(
xs
.into_iter
()
.rev
()
.fold
(
0
,
|
a
:
usize
,
b
:
usize
|
10
*
a
+
b
),
54321
);
assert_eq!
(
xs
.into_iter
()
.rev
()
.fold
(
0
,
|
a
:
usize
,
b
:
usize
|
10
*
a
+
b
),
54321
);
}
}
#[test]
#[test]
fn
test_splitator
()
{
fn
test_splitator
()
{
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
],
&
[
3
],
&
[
5
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
],
&
[
3
],
&
[
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.split
(|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[
2
,
3
,
4
,
5
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
1
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
assert_eq!
(
xs
.split
(|
x
|
*
x
==
1
)
.collect
::
<
Vec
<
_
>>
(),
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
],
&
[]];
splits
);
assert_eq!
(
xs
.split
(|
x
|
*
x
==
5
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
],
&
[]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
5
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.split
(|
x
|
*
x
==
10
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
10
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[],
&
[],
&
[]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[],
&
[],
&
[]];
assert_eq!
(
xs
.split
(|
_
|
true
)
.collect
::
<
Vec
<&
[
i32
]
>>
(),
assert_eq!
(
xs
.split
(|
_
|
true
)
.collect
::
<
Vec
<&
[
i32
]
>>
(),
splits
);
splits
);
let
xs
:
&
[
i32
]
=
&
[];
let
xs
:
&
[
i32
]
=
&
[];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
...
@@ -724,17 +725,14 @@ fn test_splitator() {
...
@@ -724,17 +725,14 @@ fn test_splitator() {
#[test]
#[test]
fn
test_splitnator
()
{
fn
test_splitnator
()
{
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.splitn
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.splitn
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
],
&
[
3
,
4
,
5
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
],
&
[
3
,
4
,
5
]];
assert_eq!
(
xs
.splitn
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
assert_eq!
(
xs
.splitn
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[
4
,
5
]];
splits
);
assert_eq!
(
xs
.splitn
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[
4
,
5
]];
assert_eq!
(
xs
.splitn
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
xs
:
&
[
i32
]
=
&
[];
let
xs
:
&
[
i32
]
=
&
[];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
...
@@ -743,40 +741,34 @@ fn test_splitnator() {
...
@@ -743,40 +741,34 @@ fn test_splitnator() {
#[test]
#[test]
fn
test_splitnator_mut
()
{
fn
test_splitnator_mut
()
{
let
xs
=
&
mut
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
&
mut
[
1
,
2
,
3
,
4
,
5
];
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[
1
,
2
,
3
,
4
,
5
]];
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.splitn_mut
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.splitn_mut
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[
1
],
&
mut
[
3
,
4
,
5
]];
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[
1
],
&
mut
[
3
,
4
,
5
]];
assert_eq!
(
xs
.splitn_mut
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.splitn_mut
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[],
&
mut
[],
&
mut
[],
&
mut
[
4
,
5
]];
let
splits
:
&
[
&
mut
[
_
]]
=
&
[
&
mut
[],
&
mut
[],
&
mut
[],
&
mut
[
4
,
5
]];
assert_eq!
(
xs
.splitn_mut
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.splitn_mut
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
xs
:
&
mut
[
i32
]
=
&
mut
[];
let
xs
:
&
mut
[
i32
]
=
&
mut
[];
let
splits
:
&
[
&
mut
[
i32
]]
=
&
[
&
mut
[]];
let
splits
:
&
[
&
mut
[
i32
]]
=
&
[
&
mut
[]];
assert_eq!
(
xs
.splitn_mut
(
2
,
|
x
|
*
x
==
5
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.splitn_mut
(
2
,
|
x
|
*
x
==
5
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
}
}
#[test]
#[test]
fn
test_rsplitator
()
{
fn
test_rsplitator
()
{
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
3
],
&
[
1
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
3
],
&
[
1
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
%
2
==
0
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.split
(|
x
|
*
x
%
2
==
0
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
2
,
3
,
4
,
5
],
&
[]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
2
,
3
,
4
,
5
],
&
[]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
1
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
splits
);
assert_eq!
(
xs
.split
(|
x
|
*
x
==
1
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[
1
,
2
,
3
,
4
]];
splits
);
assert_eq!
(
xs
.split
(|
x
|
*
x
==
5
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[
1
,
2
,
3
,
4
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
5
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.split
(|
x
|
*
x
==
10
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.split
(|
x
|
*
x
==
10
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
xs
:
&
[
i32
]
=
&
[];
let
xs
:
&
[
i32
]
=
&
[];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
...
@@ -785,19 +777,16 @@ fn test_rsplitator() {
...
@@ -785,19 +777,16 @@ fn test_rsplitator() {
#[test]
#[test]
fn
test_rsplitnator
()
{
fn
test_rsplitnator
()
{
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
xs
=
&
[
1
,
2
,
3
,
4
,
5
];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
xs
.rsplitn
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
assert_eq!
(
xs
.rsplitn
(
1
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
1
,
2
,
3
]];
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
1
,
2
,
3
]];
assert_eq!
(
xs
.rsplitn
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
assert_eq!
(
xs
.rsplitn
(
2
,
|
x
|
*
x
%
2
==
0
)
.collect
::
<
Vec
<
_
>>
(),
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[
1
,
2
]];
splits
);
assert_eq!
(
xs
.rsplitn
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
splits
:
&
[
&
[
_
]]
=
&
[
&
[],
&
[],
&
[],
&
[
1
,
2
]];
assert_eq!
(
xs
.rsplitn
(
4
,
|
_
|
true
)
.collect
::
<
Vec
<
_
>>
(),
splits
);
let
xs
:
&
[
i32
]
=
&
[];
let
xs
:
&
[
i32
]
=
&
[];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
let
splits
:
&
[
&
[
i32
]]
=
&
[
&
[]];
assert_eq!
(
xs
.rsplitn
(
2
,
|
x
|
*
x
==
5
)
.collect
::
<
Vec
<&
[
i32
]
>>
(),
splits
);
assert_eq!
(
xs
.rsplitn
(
2
,
|
x
|
*
x
==
5
)
.collect
::
<
Vec
<&
[
i32
]
>>
(),
splits
);
assert
!
(
xs
.rsplitn
(
0
,
|
x
|
*
x
%
2
==
0
)
.next
()
.is_none
());
assert
!
(
xs
.rsplitn
(
0
,
|
x
|
*
x
%
2
==
0
)
.next
()
.is_none
());
...
@@ -805,55 +794,55 @@ fn test_rsplitnator() {
...
@@ -805,55 +794,55 @@ fn test_rsplitnator() {
#[test]
#[test]
fn
test_windowsator
()
{
fn
test_windowsator
()
{
let
v
=
&
[
1
,
2
,
3
,
4
];
let
v
=
&
[
1
,
2
,
3
,
4
];
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
],
&
[
2
,
3
],
&
[
3
,
4
]];
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
],
&
[
2
,
3
],
&
[
3
,
4
]];
assert_eq!
(
v
.windows
(
2
)
.collect
::
<
Vec
<
_
>>
(),
wins
);
assert_eq!
(
v
.windows
(
2
)
.collect
::
<
Vec
<
_
>>
(),
wins
);
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
],
&
[
2
,
3
,
4
]];
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
],
&
[
2
,
3
,
4
]];
assert_eq!
(
v
.windows
(
3
)
.collect
::
<
Vec
<
_
>>
(),
wins
);
assert_eq!
(
v
.windows
(
3
)
.collect
::
<
Vec
<
_
>>
(),
wins
);
assert
!
(
v
.windows
(
6
)
.next
()
.is_none
());
assert
!
(
v
.windows
(
6
)
.next
()
.is_none
());
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
3
,
4
],
&
[
2
,
3
],
&
[
1
,
2
]];
let
wins
:
&
[
&
[
_
]]
=
&
[
&
[
3
,
4
],
&
[
2
,
3
],
&
[
1
,
2
]];
assert_eq!
(
v
.windows
(
2
)
.rev
()
.collect
::
<
Vec
<&
[
_
]
>>
(),
wins
);
assert_eq!
(
v
.windows
(
2
)
.rev
()
.collect
::
<
Vec
<&
[
_
]
>>
(),
wins
);
}
}
#[test]
#[test]
#[should_panic]
#[should_panic]
fn
test_windowsator_0
()
{
fn
test_windowsator_0
()
{
let
v
=
&
[
1
,
2
,
3
,
4
];
let
v
=
&
[
1
,
2
,
3
,
4
];
let
_
it
=
v
.windows
(
0
);
let
_
it
=
v
.windows
(
0
);
}
}
#[test]
#[test]
fn
test_chunksator
()
{
fn
test_chunksator
()
{
let
v
=
&
[
1
,
2
,
3
,
4
,
5
];
let
v
=
&
[
1
,
2
,
3
,
4
,
5
];
assert_eq!
(
v
.chunks
(
2
)
.len
(),
3
);
assert_eq!
(
v
.chunks
(
2
)
.len
(),
3
);
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
],
&
[
3
,
4
],
&
[
5
]];
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
],
&
[
3
,
4
],
&
[
5
]];
assert_eq!
(
v
.chunks
(
2
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
assert_eq!
(
v
.chunks
(
2
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
],
&
[
4
,
5
]];
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
],
&
[
4
,
5
]];
assert_eq!
(
v
.chunks
(
3
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
assert_eq!
(
v
.chunks
(
3
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
1
,
2
,
3
,
4
,
5
]];
assert_eq!
(
v
.chunks
(
6
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
assert_eq!
(
v
.chunks
(
6
)
.collect
::
<
Vec
<
_
>>
(),
chunks
);
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
3
,
4
],
&
[
1
,
2
]];
let
chunks
:
&
[
&
[
_
]]
=
&
[
&
[
5
],
&
[
3
,
4
],
&
[
1
,
2
]];
assert_eq!
(
v
.chunks
(
2
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
chunks
);
assert_eq!
(
v
.chunks
(
2
)
.rev
()
.collect
::
<
Vec
<
_
>>
(),
chunks
);
}
}
#[test]
#[test]
#[should_panic]
#[should_panic]
fn
test_chunksator_0
()
{
fn
test_chunksator_0
()
{
let
v
=
&
[
1
,
2
,
3
,
4
];
let
v
=
&
[
1
,
2
,
3
,
4
];
let
_
it
=
v
.chunks
(
0
);
let
_
it
=
v
.chunks
(
0
);
}
}
#[test]
#[test]
fn
test_reverse_part
()
{
fn
test_reverse_part
()
{
let
mut
values
=
[
1
,
2
,
3
,
4
,
5
];
let
mut
values
=
[
1
,
2
,
3
,
4
,
5
];
values
[
1
..
4
]
.reverse
();
values
[
1
..
4
]
.reverse
();
assert
!
(
values
==
[
1
,
4
,
3
,
2
,
5
]);
assert
!
(
values
==
[
1
,
4
,
3
,
2
,
5
]);
}
}
#[test]
#[test]
...
@@ -869,16 +858,15 @@ fn test_show() {
...
@@ -869,16 +858,15 @@ fn test_show() {
test_show_vec!
(
empty
,
"[]"
);
test_show_vec!
(
empty
,
"[]"
);
test_show_vec!
(
vec!
[
1
],
"[1]"
);
test_show_vec!
(
vec!
[
1
],
"[1]"
);
test_show_vec!
(
vec!
[
1
,
2
,
3
],
"[1, 2, 3]"
);
test_show_vec!
(
vec!
[
1
,
2
,
3
],
"[1, 2, 3]"
);
test_show_vec!
(
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]],
test_show_vec!
(
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]],
"[[], [1], [1, 1]]"
);
"[[], [1], [1, 1]]"
);
let
empty_mut
:
&
mut
[
i32
]
=
&
mut
[];
let
empty_mut
:
&
mut
[
i32
]
=
&
mut
[];
test_show_vec!
(
empty_mut
,
"[]"
);
test_show_vec!
(
empty_mut
,
"[]"
);
let
v
=
&
mut
[
1
];
let
v
=
&
mut
[
1
];
test_show_vec!
(
v
,
"[1]"
);
test_show_vec!
(
v
,
"[1]"
);
let
v
=
&
mut
[
1
,
2
,
3
];
let
v
=
&
mut
[
1
,
2
,
3
];
test_show_vec!
(
v
,
"[1, 2, 3]"
);
test_show_vec!
(
v
,
"[1, 2, 3]"
);
let
v
:
&
mut
[
&
mut
[
_
]]
=
&
mut
[
&
mut
[],
&
mut
[
1
],
&
mut
[
1
,
1
]];
let
v
:
&
mut
[
&
mut
[
_
]]
=
&
mut
[
&
mut
[],
&
mut
[
1
],
&
mut
[
1
,
1
]];
test_show_vec!
(
v
,
"[[], [1], [1, 1]]"
);
test_show_vec!
(
v
,
"[[], [1], [1, 1]]"
);
}
}
...
@@ -914,7 +902,7 @@ fn test_overflow_does_not_cause_segfault_managed() {
...
@@ -914,7 +902,7 @@ fn test_overflow_does_not_cause_segfault_managed() {
#[test]
#[test]
fn
test_mut_split_at
()
{
fn
test_mut_split_at
()
{
let
mut
values
=
[
1
,
2
,
3
,
4
,
5
];
let
mut
values
=
[
1
,
2
,
3
,
4
,
5
];
{
{
let
(
left
,
right
)
=
values
.split_at_mut
(
2
);
let
(
left
,
right
)
=
values
.split_at_mut
(
2
);
{
{
...
@@ -1021,32 +1009,32 @@ fn test_ends_with() {
...
@@ -1021,32 +1009,32 @@ fn test_ends_with() {
#[test]
#[test]
fn
test_mut_splitator
()
{
fn
test_mut_splitator
()
{
let
mut
xs
=
[
0
,
1
,
0
,
2
,
3
,
0
,
0
,
4
,
5
,
0
];
let
mut
xs
=
[
0
,
1
,
0
,
2
,
3
,
0
,
0
,
4
,
5
,
0
];
assert_eq!
(
xs
.split_mut
(|
x
|
*
x
==
0
)
.count
(),
6
);
assert_eq!
(
xs
.split_mut
(|
x
|
*
x
==
0
)
.count
(),
6
);
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
{
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
{
slice
.reverse
();
slice
.reverse
();
}
}
assert
!
(
xs
==
[
0
,
1
,
0
,
3
,
2
,
0
,
0
,
5
,
4
,
0
]);
assert
!
(
xs
==
[
0
,
1
,
0
,
3
,
2
,
0
,
0
,
5
,
4
,
0
]);
let
mut
xs
=
[
0
,
1
,
0
,
2
,
3
,
0
,
0
,
4
,
5
,
0
,
6
,
7
];
let
mut
xs
=
[
0
,
1
,
0
,
2
,
3
,
0
,
0
,
4
,
5
,
0
,
6
,
7
];
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
.take
(
5
)
{
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
.take
(
5
)
{
slice
.reverse
();
slice
.reverse
();
}
}
assert
!
(
xs
==
[
0
,
1
,
0
,
3
,
2
,
0
,
0
,
5
,
4
,
0
,
6
,
7
]);
assert
!
(
xs
==
[
0
,
1
,
0
,
3
,
2
,
0
,
0
,
5
,
4
,
0
,
6
,
7
]);
}
}
#[test]
#[test]
fn
test_mut_splitator_rev
()
{
fn
test_mut_splitator_rev
()
{
let
mut
xs
=
[
1
,
2
,
0
,
3
,
4
,
0
,
0
,
5
,
6
,
0
];
let
mut
xs
=
[
1
,
2
,
0
,
3
,
4
,
0
,
0
,
5
,
6
,
0
];
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
.rev
()
.take
(
4
)
{
for
slice
in
xs
.split_mut
(|
x
|
*
x
==
0
)
.rev
()
.take
(
4
)
{
slice
.reverse
();
slice
.reverse
();
}
}
assert
!
(
xs
==
[
1
,
2
,
0
,
4
,
3
,
0
,
0
,
6
,
5
,
0
]);
assert
!
(
xs
==
[
1
,
2
,
0
,
4
,
3
,
0
,
0
,
6
,
5
,
0
]);
}
}
#[test]
#[test]
fn
test_get_mut
()
{
fn
test_get_mut
()
{
let
mut
v
=
[
0
,
1
,
2
];
let
mut
v
=
[
0
,
1
,
2
];
assert_eq!
(
v
.get_mut
(
3
),
None
);
assert_eq!
(
v
.get_mut
(
3
),
None
);
v
.get_mut
(
1
)
.map
(|
e
|
*
e
=
7
);
v
.get_mut
(
1
)
.map
(|
e
|
*
e
=
7
);
assert_eq!
(
v
[
1
],
7
);
assert_eq!
(
v
[
1
],
7
);
...
@@ -1119,7 +1107,7 @@ fn test_box_slice_clone_panics() {
...
@@ -1119,7 +1107,7 @@ fn test_box_slice_clone_panics() {
struct
Canary
{
struct
Canary
{
count
:
Arc
<
AtomicUsize
>
,
count
:
Arc
<
AtomicUsize
>
,
panics
:
bool
panics
:
bool
,
}
}
impl
Drop
for
Canary
{
impl
Drop
for
Canary
{
...
@@ -1130,27 +1118,37 @@ fn drop(&mut self) {
...
@@ -1130,27 +1118,37 @@ fn drop(&mut self) {
impl
Clone
for
Canary
{
impl
Clone
for
Canary
{
fn
clone
(
&
self
)
->
Self
{
fn
clone
(
&
self
)
->
Self
{
if
self
.panics
{
panic!
()
}
if
self
.panics
{
panic!
()
}
Canary
{
Canary
{
count
:
self
.count
.clone
(),
count
:
self
.count
.clone
(),
panics
:
self
.panics
panics
:
self
.panics
,
}
}
}
}
}
}
let
drop_count
=
Arc
::
new
(
AtomicUsize
::
new
(
0
));
let
drop_count
=
Arc
::
new
(
AtomicUsize
::
new
(
0
));
let
canary
=
Canary
{
count
:
drop_count
.clone
(),
panics
:
false
};
let
canary
=
Canary
{
let
panic
=
Canary
{
count
:
drop_count
.clone
(),
panics
:
true
};
count
:
drop_count
.clone
(),
panics
:
false
,
};
let
panic
=
Canary
{
count
:
drop_count
.clone
(),
panics
:
true
,
};
spawn
(
move
||
{
spawn
(
move
||
{
// When xs is dropped, +5.
// When xs is dropped, +5.
let
xs
=
vec!
[
canary
.clone
(),
canary
.clone
(),
canary
.clone
(),
let
xs
=
vec!
[
canary
.clone
(),
canary
.clone
(),
canary
.clone
(),
panic
,
canary
]
panic
,
canary
]
.into_boxed_slice
();
.into_boxed_slice
();
// When panic is cloned, +3.
// When panic is cloned, +3.
xs
.clone
();
xs
.clone
();
})
.join
()
.unwrap_err
();
})
.join
()
.unwrap_err
();
// Total = 8
// Total = 8
assert_eq!
(
drop_count
.load
(
Ordering
::
SeqCst
),
8
);
assert_eq!
(
drop_count
.load
(
Ordering
::
SeqCst
),
8
);
...
@@ -1198,7 +1196,9 @@ fn iterator(b: &mut Bencher) {
...
@@ -1198,7 +1196,9 @@ fn iterator(b: &mut Bencher) {
sum
+=
*
x
;
sum
+=
*
x
;
}
}
// sum == 11806, to stop dead code elimination.
// sum == 11806, to stop dead code elimination.
if
sum
==
0
{
panic!
()}
if
sum
==
0
{
panic!
()
}
})
})
}
}
...
@@ -1217,8 +1217,7 @@ fn mut_iterator(b: &mut Bencher) {
...
@@ -1217,8 +1217,7 @@ fn mut_iterator(b: &mut Bencher) {
#[bench]
#[bench]
fn
concat
(
b
:
&
mut
Bencher
)
{
fn
concat
(
b
:
&
mut
Bencher
)
{
let
xss
:
Vec
<
Vec
<
i32
>>
=
let
xss
:
Vec
<
Vec
<
i32
>>
=
(
0
..
100
)
.map
(|
i
|
(
0
..
i
)
.collect
())
.collect
();
(
0
..
100
)
.map
(|
i
|
(
0
..
i
)
.collect
())
.collect
();
b
.iter
(||
{
b
.iter
(||
{
xss
.concat
();
xss
.concat
();
});
});
...
@@ -1226,11 +1225,8 @@ fn concat(b: &mut Bencher) {
...
@@ -1226,11 +1225,8 @@ fn concat(b: &mut Bencher) {
#[bench]
#[bench]
fn
join
(
b
:
&
mut
Bencher
)
{
fn
join
(
b
:
&
mut
Bencher
)
{
let
xss
:
Vec
<
Vec
<
i32
>>
=
let
xss
:
Vec
<
Vec
<
i32
>>
=
(
0
..
100
)
.map
(|
i
|
(
0
..
i
)
.collect
())
.collect
();
(
0
..
100
)
.map
(|
i
|
(
0
..
i
)
.collect
())
.collect
();
b
.iter
(||
xss
.join
(
&
0
));
b
.iter
(||
{
xss
.join
(
&
0
)
});
}
}
#[bench]
#[bench]
...
@@ -1245,17 +1241,13 @@ fn push(b: &mut Bencher) {
...
@@ -1245,17 +1241,13 @@ fn push(b: &mut Bencher) {
#[bench]
#[bench]
fn
starts_with_same_vector
(
b
:
&
mut
Bencher
)
{
fn
starts_with_same_vector
(
b
:
&
mut
Bencher
)
{
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
b
.iter
(||
{
b
.iter
(||
vec
.starts_with
(
&
vec
))
vec
.starts_with
(
&
vec
)
})
}
}
#[bench]
#[bench]
fn
starts_with_single_element
(
b
:
&
mut
Bencher
)
{
fn
starts_with_single_element
(
b
:
&
mut
Bencher
)
{
let
vec
:
Vec
<
_
>
=
vec!
[
0
];
let
vec
:
Vec
<
_
>
=
vec!
[
0
];
b
.iter
(||
{
b
.iter
(||
vec
.starts_with
(
&
vec
))
vec
.starts_with
(
&
vec
)
})
}
}
#[bench]
#[bench]
...
@@ -1263,25 +1255,19 @@ fn starts_with_diff_one_element_at_end(b: &mut Bencher) {
...
@@ -1263,25 +1255,19 @@ fn starts_with_diff_one_element_at_end(b: &mut Bencher) {
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
mut
match_vec
:
Vec
<
_
>
=
(
0
..
99
)
.collect
();
let
mut
match_vec
:
Vec
<
_
>
=
(
0
..
99
)
.collect
();
match_vec
.push
(
0
);
match_vec
.push
(
0
);
b
.iter
(||
{
b
.iter
(||
vec
.starts_with
(
&
match_vec
))
vec
.starts_with
(
&
match_vec
)
})
}
}
#[bench]
#[bench]
fn
ends_with_same_vector
(
b
:
&
mut
Bencher
)
{
fn
ends_with_same_vector
(
b
:
&
mut
Bencher
)
{
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
b
.iter
(||
{
b
.iter
(||
vec
.ends_with
(
&
vec
))
vec
.ends_with
(
&
vec
)
})
}
}
#[bench]
#[bench]
fn
ends_with_single_element
(
b
:
&
mut
Bencher
)
{
fn
ends_with_single_element
(
b
:
&
mut
Bencher
)
{
let
vec
:
Vec
<
_
>
=
vec!
[
0
];
let
vec
:
Vec
<
_
>
=
vec!
[
0
];
b
.iter
(||
{
b
.iter
(||
vec
.ends_with
(
&
vec
))
vec
.ends_with
(
&
vec
)
})
}
}
#[bench]
#[bench]
...
@@ -1289,24 +1275,18 @@ fn ends_with_diff_one_element_at_beginning(b: &mut Bencher) {
...
@@ -1289,24 +1275,18 @@ fn ends_with_diff_one_element_at_beginning(b: &mut Bencher) {
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
mut
match_vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
mut
match_vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
match_vec
[
0
]
=
200
;
match_vec
[
0
]
=
200
;
b
.iter
(||
{
b
.iter
(||
vec
.starts_with
(
&
match_vec
))
vec
.starts_with
(
&
match_vec
)
})
}
}
#[bench]
#[bench]
fn
contains_last_element
(
b
:
&
mut
Bencher
)
{
fn
contains_last_element
(
b
:
&
mut
Bencher
)
{
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
let
vec
:
Vec
<
_
>
=
(
0
..
100
)
.collect
();
b
.iter
(||
{
b
.iter
(||
vec
.contains
(
&
99
))
vec
.contains
(
&
99
)
})
}
}
#[bench]
#[bench]
fn
zero_1kb_from_elem
(
b
:
&
mut
Bencher
)
{
fn
zero_1kb_from_elem
(
b
:
&
mut
Bencher
)
{
b
.iter
(||
{
b
.iter
(||
vec!
[
0u8
;
1024
]);
vec!
[
0u8
;
1024
]
});
}
}
#[bench]
#[bench]
...
@@ -1356,8 +1336,7 @@ fn random_inserts(b: &mut Bencher) {
...
@@ -1356,8 +1336,7 @@ fn random_inserts(b: &mut Bencher) {
let
mut
v
=
vec!
[(
0
,
0
);
30
];
let
mut
v
=
vec!
[(
0
,
0
);
30
];
for
_
in
0
..
100
{
for
_
in
0
..
100
{
let
l
=
v
.len
();
let
l
=
v
.len
();
v
.insert
(
rng
.gen
::
<
usize
>
()
%
(
l
+
1
),
v
.insert
(
rng
.gen
::
<
usize
>
()
%
(
l
+
1
),
(
1
,
1
));
(
1
,
1
));
}
}
})
})
}
}
...
@@ -1418,7 +1397,8 @@ fn sort_sorted(b: &mut Bencher) {
...
@@ -1418,7 +1397,8 @@ fn sort_sorted(b: &mut Bencher) {
fn
sort_big_random_small
(
b
:
&
mut
Bencher
)
{
fn
sort_big_random_small
(
b
:
&
mut
Bencher
)
{
let
mut
rng
=
thread_rng
();
let
mut
rng
=
thread_rng
();
b
.iter
(||
{
b
.iter
(||
{
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
5
)
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
5
)
.collect
::
<
Vec
<
BigSortable
>>
();
.collect
::
<
Vec
<
BigSortable
>>
();
v
.sort
();
v
.sort
();
});
});
...
@@ -1429,7 +1409,8 @@ fn sort_big_random_small(b: &mut Bencher) {
...
@@ -1429,7 +1409,8 @@ fn sort_big_random_small(b: &mut Bencher) {
fn
sort_big_random_medium
(
b
:
&
mut
Bencher
)
{
fn
sort_big_random_medium
(
b
:
&
mut
Bencher
)
{
let
mut
rng
=
thread_rng
();
let
mut
rng
=
thread_rng
();
b
.iter
(||
{
b
.iter
(||
{
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
100
)
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
100
)
.collect
::
<
Vec
<
BigSortable
>>
();
.collect
::
<
Vec
<
BigSortable
>>
();
v
.sort
();
v
.sort
();
});
});
...
@@ -1440,7 +1421,8 @@ fn sort_big_random_medium(b: &mut Bencher) {
...
@@ -1440,7 +1421,8 @@ fn sort_big_random_medium(b: &mut Bencher) {
fn
sort_big_random_large
(
b
:
&
mut
Bencher
)
{
fn
sort_big_random_large
(
b
:
&
mut
Bencher
)
{
let
mut
rng
=
thread_rng
();
let
mut
rng
=
thread_rng
();
b
.iter
(||
{
b
.iter
(||
{
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
10000
)
let
mut
v
=
rng
.gen_iter
::
<
BigSortable
>
()
.take
(
10000
)
.collect
::
<
Vec
<
BigSortable
>>
();
.collect
::
<
Vec
<
BigSortable
>>
();
v
.sort
();
v
.sort
();
});
});
...
...
src/libcollectionstest/string.rs
浏览文件 @
3d9d96b6
...
@@ -31,8 +31,8 @@ fn into_cow(self) -> Cow<'a, str> {
...
@@ -31,8 +31,8 @@ fn into_cow(self) -> Cow<'a, str> {
#[test]
#[test]
fn
test_from_str
()
{
fn
test_from_str
()
{
let
owned
:
Option
<
::
std
::
string
::
String
>
=
"string"
.parse
()
.ok
();
let
owned
:
Option
<
::
std
::
string
::
String
>
=
"string"
.parse
()
.ok
();
assert_eq!
(
owned
.as_ref
()
.map
(|
s
|
&**
s
),
Some
(
"string"
));
assert_eq!
(
owned
.as_ref
()
.map
(|
s
|
&**
s
),
Some
(
"string"
));
}
}
#[test]
#[test]
...
@@ -44,8 +44,7 @@ fn test_unsized_to_string() {
...
@@ -44,8 +44,7 @@ fn test_unsized_to_string() {
#[test]
#[test]
fn
test_from_utf8
()
{
fn
test_from_utf8
()
{
let
xs
=
b
"hello"
.to_vec
();
let
xs
=
b
"hello"
.to_vec
();
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
String
::
from
(
"hello"
));
String
::
from
(
"hello"
));
let
xs
=
"ศไทย中华Việt Nam"
.as_bytes
()
.to_vec
();
let
xs
=
"ศไทย中华Việt Nam"
.as_bytes
()
.to_vec
();
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
assert_eq!
(
String
::
from_utf8
(
xs
)
.unwrap
(),
...
@@ -87,56 +86,40 @@ fn test_from_utf8_lossy() {
...
@@ -87,56 +86,40 @@ fn test_from_utf8_lossy() {
String
::
from
(
"
\
u{FFFD}foo
\
u{FFFD}bar
\
u{FFFD}
\
u{FFFD}baz"
)
.into_cow
());
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"
;
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}
\
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
foo
\
u{10000}bar"
)
.into_cow
());
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}
foo
\
u{10000}bar"
)
.into_cow
());
// surrogates
// surrogates
let
xs
=
b
"
\xED\xA0\x80
foo
\xED\xBF\xBF
bar"
;
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
\
assert_eq!
(
String
::
from_utf8_lossy
(
xs
),
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}bar"
)
.into_cow
());
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}foo
\
u{FFFD}
\
u{FFFD}
\
u{FFFD}bar"
)
.into_cow
());
}
}
#[test]
#[test]
fn
test_from_utf16
()
{
fn
test_from_utf16
()
{
let
pairs
=
let
pairs
=
[(
String
::
from
(
"𐍅𐌿𐌻𐍆𐌹𐌻𐌰
\n
"
),
[(
String
::
from
(
"𐍅𐌿𐌻𐍆𐌹𐌻𐌰
\n
"
),
vec!
[
0xd800
,
0xdf45
,
0xd800
,
0xdf3f
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf46
,
0xd800
,
vec!
[
0xd800
,
0xdf45
,
0xd800
,
0xdf3f
,
0xdf39
,
0xd800
,
0xdf3b
,
0xd800
,
0xdf30
,
0x000a
]),
0xd800
,
0xdf3b
,
0xd800
,
0xdf46
,
0xd800
,
0xdf39
,
0xd800
,
0xdf3b
,
(
String
::
from
(
"𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍
\n
"
),
0xd800
,
0xdf30
,
0x000a
]),
vec!
[
0xd801
,
0xdc12
,
0xd801
,
0xdc49
,
0xd801
,
0xdc2e
,
0xd801
,
0xdc40
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4b
,
0x0020
,
0xd801
,
0xdc0f
,
0xd801
,
0xdc32
,
0xd801
,
(
String
::
from
(
"𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍
\n
"
),
0xdc4d
,
0x000a
]),
vec!
[
0xd801
,
0xdc12
,
0xd801
,
0xdc49
,
0xd801
,
0xdc2e
,
0xd801
,
(
String
::
from
(
"𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑
\n
"
),
0xdc40
,
0xd801
,
0xdc32
,
0xd801
,
vec!
[
0xd800
,
0xdf00
,
0xd800
,
0xdf16
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf04
,
0xd800
,
0xdc4b
,
0x0020
,
0xd801
,
0xdc0f
,
0xdf11
,
0xd800
,
0xdf09
,
0x00b7
,
0xd800
,
0xdf0c
,
0xd800
,
0xdf04
,
0xd800
,
0xd801
,
0xdc32
,
0xd801
,
0xdc4d
,
0xdf15
,
0xd800
,
0xdf04
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf09
,
0xd800
,
0xdf11
,
0x000a
]),
0x000a
]),
(
String
::
from
(
"𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑
\n
"
),
(
String
::
from
(
"𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆
\n
"
),
vec!
[
0xd800
,
0xdf00
,
0xd800
,
0xdf16
,
vec!
[
0xd801
,
0xdc8b
,
0xd801
,
0xdc98
,
0xd801
,
0xdc88
,
0xd801
,
0xdc91
,
0xd801
,
0xd800
,
0xdf0b
,
0xd800
,
0xdf04
,
0xdc9b
,
0xd801
,
0xdc92
,
0x0020
,
0xd801
,
0xdc95
,
0xd801
,
0xdc93
,
0x0020
,
0xd800
,
0xdf11
,
0xd800
,
0xdf09
,
0xd801
,
0xdc88
,
0xd801
,
0xdc9a
,
0xd801
,
0xdc8d
,
0x0020
,
0xd801
,
0xdc8f
,
0x00b7
,
0xd800
,
0xdf0c
,
0xd800
,
0xd801
,
0xdc9c
,
0xd801
,
0xdc92
,
0xd801
,
0xdc96
,
0xd801
,
0xdc86
,
0x0020
,
0xdf04
,
0xd800
,
0xdf15
,
0xd800
,
0xd801
,
0xdc95
,
0xd801
,
0xdc86
,
0x000a
]),
0xdf04
,
0xd800
,
0xdf0b
,
0xd800
,
// Issue #12318, even-numbered non-BMP planes
0xdf09
,
0xd800
,
0xdf11
,
0x000a
]),
(
String
::
from
(
"
\
u{20000}"
),
vec!
[
0xD840
,
0xDC00
])];
(
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
{
for
p
in
&
pairs
{
let
(
s
,
u
)
=
(
*
p
)
.clone
();
let
(
s
,
u
)
=
(
*
p
)
.clone
();
...
@@ -173,13 +156,15 @@ fn test_utf16_invalid() {
...
@@ -173,13 +156,15 @@ fn test_utf16_invalid() {
fn
test_from_utf16_lossy
()
{
fn
test_from_utf16_lossy
()
{
// completely positive cases tested above.
// completely positive cases tested above.
// lead + eof
// 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
// lead + lead
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xD800
]),
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xD800
]),
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}"
));
String
::
from
(
"
\
u{FFFD}
\
u{FFFD}"
));
// isolated trail
// 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
// general
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xd801
,
0xdc8b
,
0xD800
]),
assert_eq!
(
String
::
from_utf16_lossy
(
&
[
0xD800
,
0xd801
,
0xdc8b
,
0xD800
]),
...
@@ -288,7 +273,8 @@ fn remove() {
...
@@ -288,7 +273,8 @@ fn remove() {
assert_eq!
(
s
,
"ไทย中华Vit Nam; foobar"
);
assert_eq!
(
s
,
"ไทย中华Vit Nam; foobar"
);
}
}
#[test]
#[should_panic]
#[test]
#[should_panic]
fn
remove_bad
()
{
fn
remove_bad
()
{
"ศ"
.to_string
()
.remove
(
1
);
"ศ"
.to_string
()
.remove
(
1
);
}
}
...
@@ -302,8 +288,16 @@ fn insert() {
...
@@ -302,8 +288,16 @@ fn insert() {
assert_eq!
(
s
,
"ệfooยbar"
);
assert_eq!
(
s
,
"ệfooยbar"
);
}
}
#[test]
#[should_panic]
fn
insert_bad1
()
{
""
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[test]
#[should_panic]
fn
insert_bad2
()
{
"ệ"
.to_string
()
.insert
(
1
,
't'
);
}
#[should_panic]
fn
insert_bad1
()
{
""
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[should_panic]
fn
insert_bad2
()
{
"ệ"
.to_string
()
.insert
(
1
,
't'
);
}
#[test]
#[test]
fn
test_slicing
()
{
fn
test_slicing
()
{
...
@@ -331,8 +325,7 @@ fn test_vectors() {
...
@@ -331,8 +325,7 @@ fn test_vectors() {
assert_eq!
(
format!
(
"{:?}"
,
x
),
"[]"
);
assert_eq!
(
format!
(
"{:?}"
,
x
),
"[]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
]),
"[1]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
]),
"[1]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
,
2
,
3
]),
"[1, 2, 3]"
);
assert_eq!
(
format!
(
"{:?}"
,
vec!
[
1
,
2
,
3
]),
"[1, 2, 3]"
);
assert
!
(
format!
(
"{:?}"
,
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]])
==
assert
!
(
format!
(
"{:?}"
,
vec!
[
vec!
[],
vec!
[
1
],
vec!
[
1
,
1
]])
==
"[[], [1], [1, 1]]"
);
"[[], [1], [1, 1]]"
);
}
}
#[test]
#[test]
...
@@ -390,9 +383,7 @@ fn test_into_boxed_str() {
...
@@ -390,9 +383,7 @@ fn test_into_boxed_str() {
#[bench]
#[bench]
fn
bench_with_capacity
(
b
:
&
mut
Bencher
)
{
fn
bench_with_capacity
(
b
:
&
mut
Bencher
)
{
b
.iter
(||
{
b
.iter
(||
String
::
with_capacity
(
100
));
String
::
with_capacity
(
100
)
});
}
}
#[bench]
#[bench]
...
@@ -495,25 +486,19 @@ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
...
@@ -495,25 +486,19 @@ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
fn
bench_from_str
(
b
:
&
mut
Bencher
)
{
fn
bench_from_str
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
b
.iter
(||
String
::
from
(
s
))
String
::
from
(
s
)
})
}
}
#[bench]
#[bench]
fn
bench_from
(
b
:
&
mut
Bencher
)
{
fn
bench_from
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
b
.iter
(||
String
::
from
(
s
))
String
::
from
(
s
)
})
}
}
#[bench]
#[bench]
fn
bench_to_string
(
b
:
&
mut
Bencher
)
{
fn
bench_to_string
(
b
:
&
mut
Bencher
)
{
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
let
s
=
"Hello there, the quick brown fox jumped over the lazy dog!
\
Lorem ipsum dolor sit amet, consectetur. "
;
Lorem ipsum dolor sit amet, consectetur. "
;
b
.iter
(||
{
b
.iter
(||
s
.to_string
())
s
.to_string
()
})
}
}
src/libcollectionstest/vec.rs
浏览文件 @
3d9d96b6
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
use
test
::
Bencher
;
use
test
::
Bencher
;
struct
DropCounter
<
'a
>
{
struct
DropCounter
<
'a
>
{
count
:
&
'a
mut
u32
count
:
&
'a
mut
u32
,
}
}
impl
<
'a
>
Drop
for
DropCounter
<
'a
>
{
impl
<
'a
>
Drop
for
DropCounter
<
'a
>
{
...
@@ -33,17 +33,17 @@ fn test_small_vec_struct() {
...
@@ -33,17 +33,17 @@ fn test_small_vec_struct() {
fn
test_double_drop
()
{
fn
test_double_drop
()
{
struct
TwoVec
<
T
>
{
struct
TwoVec
<
T
>
{
x
:
Vec
<
T
>
,
x
:
Vec
<
T
>
,
y
:
Vec
<
T
>
y
:
Vec
<
T
>
,
}
}
let
(
mut
count_x
,
mut
count_y
)
=
(
0
,
0
);
let
(
mut
count_x
,
mut
count_y
)
=
(
0
,
0
);
{
{
let
mut
tv
=
TwoVec
{
let
mut
tv
=
TwoVec
{
x
:
Vec
::
new
(),
x
:
Vec
::
new
(),
y
:
Vec
::
new
()
y
:
Vec
::
new
()
,
};
};
tv
.x
.push
(
DropCounter
{
count
:
&
mut
count_x
});
tv
.x
.push
(
DropCounter
{
count
:
&
mut
count_x
});
tv
.y
.push
(
DropCounter
{
count
:
&
mut
count_y
});
tv
.y
.push
(
DropCounter
{
count
:
&
mut
count_y
});
// If Vec had a drop flag, here is where it would be zeroed.
// If Vec had a drop flag, here is where it would be zeroed.
// Instead, it should rely on its internal state to prevent
// Instead, it should rely on its internal state to prevent
...
@@ -85,12 +85,16 @@ fn test_extend() {
...
@@ -85,12 +85,16 @@ fn test_extend() {
let
mut
w
=
Vec
::
new
();
let
mut
w
=
Vec
::
new
();
v
.extend
(
0
..
3
);
v
.extend
(
0
..
3
);
for
i
in
0
..
3
{
w
.push
(
i
)
}
for
i
in
0
..
3
{
w
.push
(
i
)
}
assert_eq!
(
v
,
w
);
assert_eq!
(
v
,
w
);
v
.extend
(
3
..
10
);
v
.extend
(
3
..
10
);
for
i
in
3
..
10
{
w
.push
(
i
)
}
for
i
in
3
..
10
{
w
.push
(
i
)
}
assert_eq!
(
v
,
w
);
assert_eq!
(
v
,
w
);
...
@@ -117,7 +121,7 @@ fn test_extend_ref() {
...
@@ -117,7 +121,7 @@ fn test_extend_ref() {
fn
test_slice_from_mut
()
{
fn
test_slice_from_mut
()
{
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
{
{
let
slice
=
&
mut
values
[
2
..
];
let
slice
=
&
mut
values
[
2
..
];
assert
!
(
slice
==
[
3
,
4
,
5
]);
assert
!
(
slice
==
[
3
,
4
,
5
]);
for
p
in
slice
{
for
p
in
slice
{
*
p
+=
2
;
*
p
+=
2
;
...
@@ -131,7 +135,7 @@ fn test_slice_from_mut() {
...
@@ -131,7 +135,7 @@ fn test_slice_from_mut() {
fn
test_slice_to_mut
()
{
fn
test_slice_to_mut
()
{
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
let
mut
values
=
vec!
[
1
,
2
,
3
,
4
,
5
];
{
{
let
slice
=
&
mut
values
[
..
2
];
let
slice
=
&
mut
values
[
..
2
];
assert
!
(
slice
==
[
1
,
2
]);
assert
!
(
slice
==
[
1
,
2
]);
for
p
in
slice
{
for
p
in
slice
{
*
p
+=
1
;
*
p
+=
1
;
...
@@ -169,7 +173,7 @@ fn test_split_at_mut() {
...
@@ -169,7 +173,7 @@ fn test_split_at_mut() {
#[test]
#[test]
fn
test_clone
()
{
fn
test_clone
()
{
let
v
:
Vec
<
i32
>
=
vec!
[];
let
v
:
Vec
<
i32
>
=
vec!
[];
let
w
=
vec!
(
1
,
2
,
3
)
;
let
w
=
vec!
[
1
,
2
,
3
]
;
assert_eq!
(
v
,
v
.clone
());
assert_eq!
(
v
,
v
.clone
());
...
@@ -181,9 +185,9 @@ fn test_clone() {
...
@@ -181,9 +185,9 @@ fn test_clone() {
#[test]
#[test]
fn
test_clone_from
()
{
fn
test_clone_from
()
{
let
mut
v
=
vec!
()
;
let
mut
v
=
vec!
[]
;
let
three
:
Vec
<
Box
<
_
>>
=
vec!
(
box
1
,
box
2
,
box
3
)
;
let
three
:
Vec
<
Box
<
_
>>
=
vec!
[
box
1
,
box
2
,
box
3
]
;
let
two
:
Vec
<
Box
<
_
>>
=
vec!
(
box
4
,
box
5
)
;
let
two
:
Vec
<
Box
<
_
>>
=
vec!
[
box
4
,
box
5
]
;
// zero, long
// zero, long
v
.clone_from
(
&
three
);
v
.clone_from
(
&
three
);
assert_eq!
(
v
,
three
);
assert_eq!
(
v
,
three
);
...
@@ -235,16 +239,22 @@ fn zero_sized_values() {
...
@@ -235,16 +239,22 @@ fn zero_sized_values() {
assert_eq!
(
v
.iter_mut
()
.count
(),
4
);
assert_eq!
(
v
.iter_mut
()
.count
(),
4
);
for
&
mut
()
in
&
mut
v
{}
for
&
mut
()
in
&
mut
v
{}
unsafe
{
v
.set_len
(
0
);
}
unsafe
{
v
.set_len
(
0
);
}
assert_eq!
(
v
.iter_mut
()
.count
(),
0
);
assert_eq!
(
v
.iter_mut
()
.count
(),
0
);
}
}
#[test]
#[test]
fn
test_partition
()
{
fn
test_partition
()
{
assert_eq!
(
vec!
[]
.into_iter
()
.partition
(|
x
:
&
i32
|
*
x
<
3
),
(
vec!
[],
vec!
[]));
assert_eq!
(
vec!
[]
.into_iter
()
.partition
(|
x
:
&
i32
|
*
x
<
3
),
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
4
),
(
vec!
[
1
,
2
,
3
],
vec!
[]));
(
vec!
[],
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
<
4
),
assert_eq!
(
vec!
[
1
,
2
,
3
]
.into_iter
()
.partition
(|
x
|
*
x
<
0
),
(
vec!
[],
vec!
[
1
,
2
,
3
]));
(
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]
#[test]
...
@@ -264,7 +274,9 @@ fn test_vec_truncate_drop() {
...
@@ -264,7 +274,9 @@ fn test_vec_truncate_drop() {
struct
Elem
(
i32
);
struct
Elem
(
i32
);
impl
Drop
for
Elem
{
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
}
}
...
@@ -344,7 +356,7 @@ fn test_slice_out_of_bounds_5() {
...
@@ -344,7 +356,7 @@ fn test_slice_out_of_bounds_5() {
#[test]
#[test]
#[should_panic]
#[should_panic]
fn
test_swap_remove_empty
()
{
fn
test_swap_remove_empty
()
{
let
mut
vec
=
Vec
::
<
i32
>
::
new
();
let
mut
vec
=
Vec
::
<
i32
>
::
new
();
vec
.swap_remove
(
0
);
vec
.swap_remove
(
0
);
}
}
...
@@ -386,7 +398,7 @@ fn test_drain_items() {
...
@@ -386,7 +398,7 @@ fn test_drain_items() {
vec2
.push
(
i
);
vec2
.push
(
i
);
}
}
assert_eq!
(
vec
,
[]);
assert_eq!
(
vec
,
[]);
assert_eq!
(
vec2
,
[
1
,
2
,
3
]);
assert_eq!
(
vec2
,
[
1
,
2
,
3
]);
}
}
#[test]
#[test]
...
@@ -472,7 +484,7 @@ fn test_into_iter_count() {
...
@@ -472,7 +484,7 @@ fn test_into_iter_count() {
#[test]
#[test]
fn
test_into_iter_clone
()
{
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
();
let
v
:
Vec
<
i32
>
=
it
.collect
();
assert_eq!
(
&
v
[
..
],
slice
);
assert_eq!
(
&
v
[
..
],
slice
);
}
}
...
...
src/libcollectionstest/vec_deque.rs
浏览文件 @
3d9d96b6
...
@@ -52,7 +52,7 @@ fn test_simple() {
...
@@ -52,7 +52,7 @@ fn test_simple() {
}
}
#[cfg(test)]
#[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
();
let
mut
deq
=
VecDeque
::
new
();
assert_eq!
(
deq
.len
(),
0
);
assert_eq!
(
deq
.len
(),
0
);
deq
.push_front
(
a
.clone
());
deq
.push_front
(
a
.clone
());
...
@@ -186,7 +186,7 @@ enum Taggypar<T> {
...
@@ -186,7 +186,7 @@ enum Taggypar<T> {
struct
RecCy
{
struct
RecCy
{
x
:
i32
,
x
:
i32
,
y
:
i32
,
y
:
i32
,
t
:
Taggy
t
:
Taggy
,
}
}
#[test]
#[test]
...
@@ -209,10 +209,26 @@ fn test_param_taggypar() {
...
@@ -209,10 +209,26 @@ fn test_param_taggypar() {
#[test]
#[test]
fn
test_param_reccy
()
{
fn
test_param_reccy
()
{
let
reccy1
=
RecCy
{
x
:
1
,
y
:
2
,
t
:
One
(
1
)
};
let
reccy1
=
RecCy
{
let
reccy2
=
RecCy
{
x
:
345
,
y
:
2
,
t
:
Two
(
1
,
2
)
};
x
:
1
,
let
reccy3
=
RecCy
{
x
:
1
,
y
:
777
,
t
:
Three
(
1
,
2
,
3
)
};
y
:
2
,
let
reccy4
=
RecCy
{
x
:
19
,
y
:
252
,
t
:
Two
(
17
,
42
)
};
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
);
test_parameterized
::
<
RecCy
>
(
reccy1
,
reccy2
,
reccy3
,
reccy4
);
}
}
...
@@ -257,13 +273,13 @@ fn test_with_capacity_non_power_two() {
...
@@ -257,13 +273,13 @@ fn test_with_capacity_non_power_two() {
// underlying Vec which didn't hold and lead
// underlying Vec which didn't hold and lead
// to corruption.
// to corruption.
// (Vec grows to next power of two)
// (Vec grows to next power of two)
//good- [9, 12, 15, X, X, X, X, |6]
//
good- [9, 12, 15, X, X, X, X, |6]
//bug- [15, 12, X, X, X, |6, X, X]
//
bug- [15, 12, X, X, X, |6, X, X]
assert_eq!
(
d3
.pop_front
(),
Some
(
6
));
assert_eq!
(
d3
.pop_front
(),
Some
(
6
));
// Which leads us to the following state which
// Which leads us to the following state which
// would be a failure case.
// 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
));
assert_eq!
(
d3
.front
(),
Some
(
&
9
));
}
}
...
@@ -301,7 +317,7 @@ fn test_iter() {
...
@@ -301,7 +317,7 @@ fn test_iter() {
d
.push_back
(
i
);
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
);
assert_eq!
(
d
.iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
...
@@ -309,7 +325,7 @@ fn test_iter() {
...
@@ -309,7 +325,7 @@ fn test_iter() {
d
.push_front
(
i
);
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
);
assert_eq!
(
d
.iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
...
@@ -318,7 +334,10 @@ fn test_iter() {
...
@@ -318,7 +334,10 @@ fn test_iter() {
loop
{
loop
{
match
it
.next
()
{
match
it
.next
()
{
None
=>
break
,
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() {
...
@@ -332,14 +351,14 @@ fn test_rev_iter() {
d
.push_back
(
i
);
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
);
assert_eq!
(
d
.iter
()
.rev
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
for
i
in
6
..
9
{
for
i
in
6
..
9
{
d
.push_front
(
i
);
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
);
assert_eq!
(
d
.iter
()
.rev
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
...
@@ -424,7 +443,7 @@ fn test_into_iter() {
...
@@ -424,7 +443,7 @@ fn test_into_iter() {
d
.push_back
(
i
);
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
);
assert_eq!
(
d
.into_iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
...
@@ -438,7 +457,7 @@ fn test_into_iter() {
...
@@ -438,7 +457,7 @@ fn test_into_iter() {
d
.push_front
(
i
);
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
);
assert_eq!
(
d
.into_iter
()
.collect
::
<
Vec
<
_
>>
(),
b
);
}
}
...
@@ -502,7 +521,7 @@ fn test_drain() {
...
@@ -502,7 +521,7 @@ fn test_drain() {
d
.push_front
(
i
);
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
());
assert
!
(
d
.is_empty
());
}
}
...
@@ -532,7 +551,7 @@ fn test_drain() {
...
@@ -532,7 +551,7 @@ fn test_drain() {
#[test]
#[test]
fn
test_from_iter
()
{
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
deq
:
VecDeque
<
_
>
=
v
.iter
()
.cloned
()
.collect
();
let
u
:
Vec
<
_
>
=
deq
.iter
()
.cloned
()
.collect
();
let
u
:
Vec
<
_
>
=
deq
.iter
()
.cloned
()
.collect
();
assert_eq!
(
u
,
v
);
assert_eq!
(
u
,
v
);
...
@@ -540,7 +559,7 @@ fn test_from_iter() {
...
@@ -540,7 +559,7 @@ fn test_from_iter() {
let
seq
=
(
0
..
)
.step_by
(
2
)
.take
(
256
);
let
seq
=
(
0
..
)
.step_by
(
2
)
.take
(
256
);
let
deq
:
VecDeque
<
_
>
=
seq
.collect
();
let
deq
:
VecDeque
<
_
>
=
seq
.collect
();
for
(
i
,
&
x
)
in
deq
.iter
()
.enumerate
()
{
for
(
i
,
&
x
)
in
deq
.iter
()
.enumerate
()
{
assert_eq!
(
2
*
i
,
x
);
assert_eq!
(
2
*
i
,
x
);
}
}
assert_eq!
(
deq
.len
(),
256
);
assert_eq!
(
deq
.len
(),
256
);
}
}
...
@@ -585,20 +604,20 @@ fn test_eq() {
...
@@ -585,20 +604,20 @@ fn test_eq() {
#[test]
#[test]
fn
test_hash
()
{
fn
test_hash
()
{
let
mut
x
=
VecDeque
::
new
();
let
mut
x
=
VecDeque
::
new
();
let
mut
y
=
VecDeque
::
new
();
let
mut
y
=
VecDeque
::
new
();
x
.push_back
(
1
);
x
.push_back
(
1
);
x
.push_back
(
2
);
x
.push_back
(
2
);
x
.push_back
(
3
);
x
.push_back
(
3
);
y
.push_back
(
0
);
y
.push_back
(
0
);
y
.push_back
(
1
);
y
.push_back
(
1
);
y
.pop_front
();
y
.pop_front
();
y
.push_back
(
2
);
y
.push_back
(
2
);
y
.push_back
(
3
);
y
.push_back
(
3
);
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
assert
!
(::
hash
(
&
x
)
==
::
hash
(
&
y
));
}
}
#[test]
#[test]
...
@@ -665,10 +684,12 @@ fn test_show() {
...
@@ -665,10 +684,12 @@ fn test_show() {
let
ringbuf
:
VecDeque
<
_
>
=
(
0
..
10
)
.collect
();
let
ringbuf
:
VecDeque
<
_
>
=
(
0
..
10
)
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
);
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
);
let
ringbuf
:
VecDeque
<
_
>
=
vec!
[
"just"
,
"one"
,
"test"
,
"more"
]
.iter
()
let
ringbuf
:
VecDeque
<
_
>
=
vec!
[
"just"
,
"one"
,
"test"
,
"more"
]
.cloned
()
.iter
()
.collect
();
.cloned
()
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
.collect
();
assert_eq!
(
format!
(
"{:?}"
,
ringbuf
),
"[
\"
just
\"
,
\"
one
\"
,
\"
test
\"
,
\"
more
\"
]"
);
}
}
#[test]
#[test]
...
@@ -677,7 +698,9 @@ fn test_drop() {
...
@@ -677,7 +698,9 @@ fn test_drop() {
struct
Elem
;
struct
Elem
;
impl
Drop
for
Elem
{
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
}
}
...
@@ -688,7 +711,7 @@ fn drop(&mut self) {
...
@@ -688,7 +711,7 @@ fn drop(&mut self) {
ring
.push_front
(
Elem
);
ring
.push_front
(
Elem
);
drop
(
ring
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
}
#[test]
#[test]
...
@@ -697,7 +720,9 @@ fn test_drop_with_pop() {
...
@@ -697,7 +720,9 @@ fn test_drop_with_pop() {
struct
Elem
;
struct
Elem
;
impl
Drop
for
Elem
{
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
}
}
...
@@ -709,10 +734,10 @@ fn drop(&mut self) {
...
@@ -709,10 +734,10 @@ fn drop(&mut self) {
drop
(
ring
.pop_back
());
drop
(
ring
.pop_back
());
drop
(
ring
.pop_front
());
drop
(
ring
.pop_front
());
assert_eq!
(
unsafe
{
drops
},
2
);
assert_eq!
(
unsafe
{
drops
},
2
);
drop
(
ring
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
}
#[test]
#[test]
...
@@ -721,7 +746,9 @@ fn test_drop_clear() {
...
@@ -721,7 +746,9 @@ fn test_drop_clear() {
struct
Elem
;
struct
Elem
;
impl
Drop
for
Elem
{
impl
Drop
for
Elem
{
fn
drop
(
&
mut
self
)
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drops
+=
1
;
}
unsafe
{
drops
+=
1
;
}
}
}
}
}
...
@@ -731,10 +758,10 @@ fn drop(&mut self) {
...
@@ -731,10 +758,10 @@ fn drop(&mut self) {
ring
.push_back
(
Elem
);
ring
.push_back
(
Elem
);
ring
.push_front
(
Elem
);
ring
.push_front
(
Elem
);
ring
.clear
();
ring
.clear
();
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
drop
(
ring
);
drop
(
ring
);
assert_eq!
(
unsafe
{
drops
},
4
);
assert_eq!
(
unsafe
{
drops
},
4
);
}
}
#[test]
#[test]
...
@@ -822,7 +849,7 @@ fn test_get_mut() {
...
@@ -822,7 +849,7 @@ fn test_get_mut() {
match
ring
.get_mut
(
1
)
{
match
ring
.get_mut
(
1
)
{
Some
(
x
)
=>
*
x
=
-
1
,
Some
(
x
)
=>
*
x
=
-
1
,
None
=>
()
None
=>
()
,
};
};
assert_eq!
(
ring
.get_mut
(
0
),
Some
(
&
mut
0
));
assert_eq!
(
ring
.get_mut
(
0
),
Some
(
&
mut
0
));
...
@@ -852,13 +879,13 @@ fn test_front() {
...
@@ -852,13 +879,13 @@ fn test_front() {
fn
test_as_slices
()
{
fn
test_as_slices
()
{
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
cap
=
ring
.capacity
()
as
i32
;
let
cap
=
ring
.capacity
()
as
i32
;
let
first
=
cap
/
2
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
let
last
=
cap
-
first
;
for
i
in
0
..
first
{
for
i
in
0
..
first
{
ring
.push_back
(
i
);
ring
.push_back
(
i
);
let
(
left
,
right
)
=
ring
.as_slices
();
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!
(
left
,
&
expected
[
..
]);
assert_eq!
(
right
,
[]);
assert_eq!
(
right
,
[]);
}
}
...
@@ -866,7 +893,7 @@ fn test_as_slices() {
...
@@ -866,7 +893,7 @@ fn test_as_slices() {
for
j
in
-
last
..
0
{
for
j
in
-
last
..
0
{
ring
.push_front
(
j
);
ring
.push_front
(
j
);
let
(
left
,
right
)
=
ring
.as_slices
();
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
();
let
expected_right
:
Vec
<
_
>
=
(
0
..
first
)
.collect
();
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
...
@@ -880,13 +907,13 @@ fn test_as_slices() {
...
@@ -880,13 +907,13 @@ fn test_as_slices() {
fn
test_as_mut_slices
()
{
fn
test_as_mut_slices
()
{
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
mut
ring
:
VecDeque
<
i32
>
=
VecDeque
::
with_capacity
(
127
);
let
cap
=
ring
.capacity
()
as
i32
;
let
cap
=
ring
.capacity
()
as
i32
;
let
first
=
cap
/
2
;
let
first
=
cap
/
2
;
let
last
=
cap
-
first
;
let
last
=
cap
-
first
;
for
i
in
0
..
first
{
for
i
in
0
..
first
{
ring
.push_back
(
i
);
ring
.push_back
(
i
);
let
(
left
,
right
)
=
ring
.as_mut_slices
();
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!
(
left
,
&
expected
[
..
]);
assert_eq!
(
right
,
[]);
assert_eq!
(
right
,
[]);
}
}
...
@@ -894,7 +921,7 @@ fn test_as_mut_slices() {
...
@@ -894,7 +921,7 @@ fn test_as_mut_slices() {
for
j
in
-
last
..
0
{
for
j
in
-
last
..
0
{
ring
.push_front
(
j
);
ring
.push_front
(
j
);
let
(
left
,
right
)
=
ring
.as_mut_slices
();
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
();
let
expected_right
:
Vec
<
_
>
=
(
0
..
first
)
.collect
();
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
left
,
&
expected_left
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
assert_eq!
(
right
,
&
expected_right
[
..
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录