Skip to content

Commit 37b85b6

Browse files
authored
Merge pull request #24 from statiolake/ja-all-enabled
Add `num-traits` to Cargo.toml
2 parents a1e2a76 + 0d59e70 commit 37b85b6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ default = ["jemalloc"]
1919
# 多バイト長整数、分数、複素数など
2020
num = "=0.2.0"
2121
num-derive = "=0.3.0"
22+
# num-derive が依存するため必要
23+
num-traits = "=0.2.9"
2224

2325
# 多次元配列
2426
ndarray = "=0.13.0"

tests/test_num_derive.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use num_derive::{FromPrimitive, Num, NumCast, NumOps, One, ToPrimitive, Zero};
2+
3+
#[derive(
4+
Debug,
5+
Clone,
6+
Copy,
7+
PartialEq,
8+
Eq,
9+
PartialOrd,
10+
Ord,
11+
FromPrimitive,
12+
ToPrimitive,
13+
Zero,
14+
One,
15+
Num,
16+
NumCast,
17+
NumOps,
18+
)]
19+
struct Weight(i32);
20+
21+
#[test]
22+
fn check_ops() {
23+
let w1 = Weight(7);
24+
let w2 = Weight(4);
25+
26+
assert_eq!(w1 + w2, Weight(11));
27+
assert_eq!(w1 - w2, Weight(3));
28+
assert_eq!(w1 * w2, Weight(28));
29+
assert_eq!(w1 / w2, Weight(1));
30+
assert_eq!(w1 % w2, Weight(3));
31+
assert!(w1 > w2);
32+
assert!(w2 < w1);
33+
assert!(w1 >= w1);
34+
assert!(w1 <= w1);
35+
assert!(w1 != w2);
36+
assert!(w1 == w1);
37+
}

0 commit comments

Comments
 (0)