Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c4685477
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,发现更多精彩内容 >>
提交
c4685477
编写于
4月 14, 2013
作者:
B
Brendan Zabarauskas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consolidate tests of numeric operations
上级
ce6ee7bb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
29 addition
and
83 deletion
+29
-83
src/libcore/num/f32.rs
src/libcore/num/f32.rs
+0
-12
src/libcore/num/f64.rs
src/libcore/num/f64.rs
+0
-12
src/libcore/num/float.rs
src/libcore/num/float.rs
+0
-12
src/libcore/num/int-template.rs
src/libcore/num/int-template.rs
+0
-12
src/libcore/num/num.rs
src/libcore/num/num.rs
+29
-23
src/libcore/num/uint-template.rs
src/libcore/num/uint-template.rs
+0
-12
未找到文件。
src/libcore/num/f32.rs
浏览文件 @
c4685477
...
...
@@ -555,18 +555,6 @@ fn from_str_radix(val: &str, rdx: uint) -> Option<f32> {
}
}
#[test]
pub
fn
test_num
()
{
let
ten
:
f32
=
num
::
cast
(
10
);
let
two
:
f32
=
num
::
cast
(
2
);
assert
!
((
ten
.add
(
&
two
)
==
num
::
cast
(
12
)));
assert
!
((
ten
.sub
(
&
two
)
==
num
::
cast
(
8
)));
assert
!
((
ten
.mul
(
&
two
)
==
num
::
cast
(
20
)));
assert
!
((
ten
.div
(
&
two
)
==
num
::
cast
(
5
)));
assert
!
((
ten
.modulo
(
&
two
)
==
num
::
cast
(
0
)));
}
//
// Local Variables:
// mode: rust
...
...
src/libcore/num/f64.rs
浏览文件 @
c4685477
...
...
@@ -577,18 +577,6 @@ fn from_str_radix(val: &str, rdx: uint) -> Option<f64> {
}
}
#[test]
pub
fn
test_num
()
{
let
ten
:
f64
=
num
::
cast
(
10
);
let
two
:
f64
=
num
::
cast
(
2
);
assert
!
((
ten
.add
(
&
two
)
==
num
::
cast
(
12
)));
assert
!
((
ten
.sub
(
&
two
)
==
num
::
cast
(
8
)));
assert
!
((
ten
.mul
(
&
two
)
==
num
::
cast
(
20
)));
assert
!
((
ten
.div
(
&
two
)
==
num
::
cast
(
5
)));
assert
!
((
ten
.modulo
(
&
two
)
==
num
::
cast
(
0
)));
}
//
// Local Variables:
// mode: rust
...
...
src/libcore/num/float.rs
浏览文件 @
c4685477
...
...
@@ -663,18 +663,6 @@ pub fn test_round() {
assert
!
(
round
(
-
3.5
)
==
-
4.0
);
}
#[test]
pub
fn
test_num
()
{
let
ten
:
float
=
num
::
cast
(
10
);
let
two
:
float
=
num
::
cast
(
2
);
assert
!
((
ten
.add
(
&
two
)
==
num
::
cast
(
12
)));
assert
!
((
ten
.sub
(
&
two
)
==
num
::
cast
(
8
)));
assert
!
((
ten
.mul
(
&
two
)
==
num
::
cast
(
20
)));
assert
!
((
ten
.div
(
&
two
)
==
num
::
cast
(
5
)));
assert
!
((
ten
.modulo
(
&
two
)
==
num
::
cast
(
0
)));
}
//
// Local Variables:
...
...
src/libcore/num/int-template.rs
浏览文件 @
c4685477
...
...
@@ -397,18 +397,6 @@ fn test_int_from_str_overflow() {
assert
!
((
i64
::
from_str
(
~
"-9223372036854775809"
)
.is_none
()));
}
#[test]
pub
fn
test_num
()
{
let
ten
:
T
=
num
::
cast
(
10
);
let
two
:
T
=
num
::
cast
(
2
);
assert
!
((
ten
.add
(
&
two
)
==
num
::
cast
(
12
)));
assert
!
((
ten
.sub
(
&
two
)
==
num
::
cast
(
8
)));
assert
!
((
ten
.mul
(
&
two
)
==
num
::
cast
(
20
)));
assert
!
((
ten
.div
(
&
two
)
==
num
::
cast
(
5
)));
assert
!
((
ten
.modulo
(
&
two
)
==
num
::
cast
(
0
)));
}
#[test]
pub
fn
test_ranges
()
{
let
mut
l
=
~
[];
...
...
src/libcore/num/num.rs
浏览文件 @
c4685477
...
...
@@ -202,6 +202,35 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
total
}
#[cfg(test)]
fn
test_num
<
T
:
Num
+
NumCast
>
(
ten
:
T
,
two
:
T
)
{
assert
!
(
ten
.add
(
&
two
)
==
cast
(
12
));
assert
!
(
ten
.sub
(
&
two
)
==
cast
(
8
));
assert
!
(
ten
.mul
(
&
two
)
==
cast
(
20
));
assert
!
(
ten
.div
(
&
two
)
==
cast
(
5
));
assert
!
(
ten
.modulo
(
&
two
)
==
cast
(
0
));
assert
!
(
ten
.add
(
&
two
)
==
ten
+
two
);
assert
!
(
ten
.sub
(
&
two
)
==
ten
-
two
);
assert
!
(
ten
.mul
(
&
two
)
==
ten
*
two
);
assert
!
(
ten
.div
(
&
two
)
==
ten
/
two
);
assert
!
(
ten
.modulo
(
&
two
)
==
ten
%
two
);
}
#[test]
fn
test_u8_num
()
{
test_num
(
10u8
,
2u8
)
}
#[test]
fn
test_u16_num
()
{
test_num
(
10u16
,
2u16
)
}
#[test]
fn
test_u32_num
()
{
test_num
(
10u32
,
2u32
)
}
#[test]
fn
test_u64_num
()
{
test_num
(
10u64
,
2u64
)
}
#[test]
fn
test_uint_num
()
{
test_num
(
10u
,
2u
)
}
#[test]
fn
test_i8_num
()
{
test_num
(
10i8
,
2i8
)
}
#[test]
fn
test_i16_num
()
{
test_num
(
10i16
,
2i16
)
}
#[test]
fn
test_i32_num
()
{
test_num
(
10i32
,
2i32
)
}
#[test]
fn
test_i64_num
()
{
test_num
(
10i64
,
2i64
)
}
#[test]
fn
test_int_num
()
{
test_num
(
10
i
,
2
i
)
}
#[test]
fn
test_f32_num
()
{
test_num
(
10f32
,
2f32
)
}
#[test]
fn
test_f64_num
()
{
test_num
(
10f64
,
2f64
)
}
#[test]
fn
test_float_num
()
{
test_num
(
10
f
,
2
f
)
}
macro_rules!
test_cast_20
(
(
$_20:expr
)
=>
({
let
_20
=
$_20
;
...
...
@@ -263,26 +292,3 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
#[test]
fn
test_f32_cast
()
{
test_cast_20!
(
20f32
)
}
#[test]
fn
test_f64_cast
()
{
test_cast_20!
(
20f64
)
}
#[test]
fn
test_float_cast
()
{
test_cast_20!
(
20
f
)
}
#[test]
fn
test_generic_cast
()
{
use
ops
::
Add
;
fn
add_2
<
T
:
Add
<
T
,
T
>
+
NumCast
>
(
n
:
T
)
->
T
{
n
+
cast
(
2
)
}
assert
!
(
add_2
(
1u
)
==
3u
);
assert
!
(
add_2
(
1u8
)
==
3u8
);
assert
!
(
add_2
(
1u16
)
==
3u16
);
assert
!
(
add_2
(
1u32
)
==
3u32
);
assert
!
(
add_2
(
1u64
)
==
3u64
);
assert
!
(
add_2
(
1
i
)
==
3
i
);
assert
!
(
add_2
(
1i8
)
==
3i8
);
assert
!
(
add_2
(
1i16
)
==
3i16
);
assert
!
(
add_2
(
1i32
)
==
3i32
);
assert
!
(
add_2
(
1i64
)
==
3i64
);
assert
!
(
add_2
(
1
f
)
==
3
f
);
assert
!
(
add_2
(
1f32
)
==
3f32
);
assert
!
(
add_2
(
1f64
)
==
3f64
);
}
src/libcore/num/uint-template.rs
浏览文件 @
c4685477
...
...
@@ -411,18 +411,6 @@ pub fn test_ranges() {
}
}
#[test]
pub
fn
test_num
()
{
let
ten
:
T
=
num
::
cast
(
10
);
let
two
:
T
=
num
::
cast
(
2
);
assert
!
((
ten
.add
(
&
two
)
==
num
::
cast
(
12
)));
assert
!
((
ten
.sub
(
&
two
)
==
num
::
cast
(
8
)));
assert
!
((
ten
.mul
(
&
two
)
==
num
::
cast
(
20
)));
assert
!
((
ten
.div
(
&
two
)
==
num
::
cast
(
5
)));
assert
!
((
ten
.modulo
(
&
two
)
==
num
::
cast
(
0
)));
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录