Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a05c4a1e
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,发现更多精彩内容 >>
提交
a05c4a1e
编写于
9月 15, 2013
作者:
D
Daniel Micay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove old internal iterator range tests
The cases they test are well covered in the `std::iter` tests.
上级
6e3d5c62
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
254 deletion
+0
-254
src/test/run-pass/num-range-rev.rs
src/test/run-pass/num-range-rev.rs
+0
-126
src/test/run-pass/num-range.rs
src/test/run-pass/num-range.rs
+0
-128
未找到文件。
src/test/run-pass/num-range-rev.rs
已删除
100644 → 0
浏览文件 @
6e3d5c62
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
int
;
use
std
::
uint
;
fn
uint_range
(
lo
:
uint
,
hi
:
uint
,
it
:
&
fn
(
uint
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.advance
(
it
)
}
fn
int_range
(
lo
:
int
,
hi
:
int
,
it
:
&
fn
(
int
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.advance
(
it
)
}
fn
uint_range_rev
(
hi
:
uint
,
lo
:
uint
,
it
:
&
fn
(
uint
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.invert
()
.advance
(
it
)
}
fn
int_range_rev
(
hi
:
int
,
lo
:
int
,
it
:
&
fn
(
int
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.invert
()
.advance
(
it
)
}
fn
int_range_step
(
a
:
int
,
b
:
int
,
step
:
int
,
it
:
&
fn
(
int
)
->
bool
)
->
bool
{
std
::
iter
::
range_step
(
a
,
b
,
step
)
.advance
(
it
)
}
fn
uint_range_step
(
a
:
uint
,
b
:
uint
,
step
:
int
,
it
:
&
fn
(
uint
)
->
bool
)
->
bool
{
std
::
iter
::
range_step
(
a
,
b
,
step
)
.advance
(
it
)
}
pub
fn
main
()
{
// int and uint have same result for
// Sum{100 > i >= 2} == (Sum{1 <= i <= 99} - 1) == n*(n+1)/2 - 1 for n=99
let
mut
sum
=
0u
;
do
uint_range_rev
(
100
,
2
)
|
i
|
{
sum
+=
i
;
true
};
assert_eq!
(
sum
,
4949
);
let
mut
sum
=
0
i
;
do
int_range_rev
(
100
,
2
)
|
i
|
{
sum
+=
i
;
true
};
assert_eq!
(
sum
,
4949
);
// elements are visited in correct order
let
primes
=
[
2
,
3
,
5
,
7
,
11
];
let
mut
prod
=
1
i
;
do
uint_range_rev
(
5
,
0
)
|
i
|
{
printfln!
(
"uint 4 downto 0: %u"
,
i
);
prod
*=
int
::
pow
(
primes
[
i
],
i
);
true
};
assert_eq!
(
prod
,
11
*
11
*
11
*
11
*
7
*
7
*
7
*
5
*
5
*
3
*
1
);
let
mut
prod
=
1
i
;
do
int_range_rev
(
5
,
0
)
|
i
|
{
printfln!
(
"int 4 downto 0: %d"
,
i
);
prod
*=
int
::
pow
(
primes
[
i
],
i
as
uint
);
true
};
assert_eq!
(
prod
,
11
*
11
*
11
*
11
*
7
*
7
*
7
*
5
*
5
*
3
*
1
);
// range and range_rev are symmetric.
let
mut
sum_up
=
0u
;
do
uint_range
(
10
,
30
)
|
i
|
{
sum_up
+=
i
;
true
};
let
mut
sum_down
=
0u
;
do
uint_range_rev
(
30
,
10
)
|
i
|
{
sum_down
+=
i
;
true
};
assert_eq!
(
sum_up
,
sum_down
);
let
mut
sum_up
=
0
;
do
int_range
(
-
20
,
10
)
|
i
|
{
sum_up
+=
i
;
true
};
let
mut
sum_down
=
0
;
do
int_range_rev
(
10
,
-
20
)
|
i
|
{
sum_down
+=
i
;
true
};
assert_eq!
(
sum_up
,
sum_down
);
// empty ranges
do
int_range_rev
(
10
,
10
)
|
_
|
{
fail
!
(
"range should be empty when start == stop"
);
true
};
do
uint_range_rev
(
0
,
1
)
|
_
|
{
fail
!
(
"range should be empty when start-1 underflows"
);
true
};
// range iterations do not wrap/underflow
let
mut
uflo_loop_visited
=
~
[];
do
int_range_step
(
int
::
min_value
+
15
,
int
::
min_value
,
-
4
)
|
x
|
{
uflo_loop_visited
.push
(
x
-
int
::
min_value
);
true
};
assert_eq!
(
uflo_loop_visited
,
~
[
15
,
11
,
7
,
3
]);
let
mut
uflo_loop_visited
=
~
[];
do
uint_range_step
(
uint
::
min_value
+
15
,
uint
::
min_value
,
-
4
)
|
x
|
{
uflo_loop_visited
.push
(
x
-
uint
::
min_value
);
true
};
assert_eq!
(
uflo_loop_visited
,
~
[
15
,
11
,
7
,
3
]);
}
src/test/run-pass/num-range.rs
已删除
100644 → 0
浏览文件 @
6e3d5c62
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
int
;
use
std
::
uint
;
fn
uint_range
(
lo
:
uint
,
hi
:
uint
,
it
:
&
fn
(
uint
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.advance
(
it
)
}
fn
int_range
(
lo
:
int
,
hi
:
int
,
it
:
&
fn
(
int
)
->
bool
)
->
bool
{
range
(
lo
,
hi
)
.advance
(
it
)
}
fn
int_range_step
(
a
:
int
,
b
:
int
,
step
:
int
,
it
:
&
fn
(
int
)
->
bool
)
->
bool
{
std
::
iter
::
range_step
(
a
,
b
,
step
)
.advance
(
it
)
}
fn
uint_range_step
(
a
:
uint
,
b
:
uint
,
s
:
int
,
it
:
&
fn
(
uint
)
->
bool
)
->
bool
{
std
::
iter
::
range_step
(
a
,
b
,
s
)
.advance
(
it
)
}
pub
fn
main
()
{
println
(
"num-range start"
);
// int and uint have same result for
// Sum{2 <= i < 100} == (Sum{1 <= i <= 99} - 1) == n*(n+1)/2 - 1 for n=99
let
mut
sum
=
0u
;
do
uint_range
(
2
,
100
)
|
i
|
{
sum
+=
i
;
true
};
assert_eq!
(
sum
,
4949
);
let
mut
sum
=
0
i
;
do
int_range
(
2
,
100
)
|
i
|
{
sum
+=
i
;
true
};
assert_eq!
(
sum
,
4949
);
// elements are visited in correct order
let
primes
=
[
2
,
3
,
5
,
7
];
let
mut
prod
=
1
i
;
do
uint_range
(
0
,
4
)
|
i
|
{
prod
*=
int
::
pow
(
primes
[
i
],
i
);
true
};
assert_eq!
(
prod
,
1
*
3
*
5
*
5
*
7
*
7
*
7
);
let
mut
prod
=
1
i
;
do
int_range
(
0
,
4
)
|
i
|
{
prod
*=
int
::
pow
(
primes
[
i
],
i
as
uint
);
true
};
assert_eq!
(
prod
,
1
*
3
*
5
*
5
*
7
*
7
*
7
);
// empty ranges
do
int_range
(
10
,
10
)
|
_
|
{
fail
!
(
"range should be empty when start == stop"
);
true
};
do
uint_range
(
10
,
10
)
|
_
|
{
fail
!
(
"range should be empty when start == stop"
);
true
};
// range iterations do not wrap/overflow
let
mut
oflo_loop_visited
=
~
[];
do
uint_range_step
(
uint
::
max_value
-
15
,
uint
::
max_value
,
4
)
|
x
|
{
oflo_loop_visited
.push
(
uint
::
max_value
-
x
);
true
};
assert_eq!
(
oflo_loop_visited
,
~
[
15
,
11
,
7
,
3
]);
let
mut
oflo_loop_visited
=
~
[];
do
int_range_step
(
int
::
max_value
-
15
,
int
::
max_value
,
4
)
|
x
|
{
oflo_loop_visited
.push
(
int
::
max_value
-
x
);
true
};
assert_eq!
(
oflo_loop_visited
,
~
[
15
,
11
,
7
,
3
]);
// range_step never passes nor visits the stop element
do
int_range_step
(
0
,
21
,
3
)
|
x
|
{
assert
!
(
x
<
21
);
true
};
// range_step_inclusive will never pass stop element, and may skip it.
let
mut
saw21
=
false
;
for
x
in
std
::
iter
::
range_step_inclusive
(
0
,
21
,
4
)
{
assert
!
(
x
<=
21
);
if
x
==
21
{
saw21
=
true
;
}
}
assert
!
(
!
saw21
);
let
mut
saw21
=
false
;
for
x
in
std
::
iter
::
range_step_inclusive
(
0
,
21
,
4
)
{
assert
!
(
x
<=
21
);
if
x
==
21
{
saw21
=
true
;
}
}
assert
!
(
!
saw21
);
// range_step_inclusive will never pass stop element, but may visit it.
let
mut
saw21
=
false
;
for
x
in
std
::
iter
::
range_step_inclusive
(
0
,
21
,
3
)
{
assert
!
(
x
<=
21
);
printfln!
(
"saw: %u"
,
x
);
if
x
==
21
{
saw21
=
true
;
}
}
assert
!
(
saw21
);
let
mut
saw21
=
false
;
for
x
in
std
::
iter
::
range_step_inclusive
(
0
,
21
,
3
)
{
assert
!
(
x
<=
21
);
if
x
==
21
{
saw21
=
true
;
}
}
assert
!
(
saw21
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录