1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use core::ops::Sub;
use crate::BigNumber;
impl Sub for BigNumber {
type Output = BigNumber;
fn sub(self, rhs: Self) -> Self::Output {
BigNumber {
value: self.value.sub(rhs.value)
}
}
}
#[cfg(test)]
mod tests {
use crate::to_bn_safe;
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
#[test]
fn test_a() {
assert_eq!(
to_bn_safe!("1").sub(to_bn_safe!("3")).to_string(),
"-2"
);
}
#[test]
fn test_b() {
assert_eq!(
to_bn_safe!("0.3").sub(to_bn_safe!("0.2")).to_string(),
"0.1"
);
}
}