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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use honggfuzz::fuzz;
use sp_arithmetic::{traits::Saturating, FixedI64, FixedPointNumber};
fn main() {
loop {
fuzz!(|data: (i32, i32)| {
let x: i128 = data.0.into();
let y: i128 = data.1.into();
if y != 0 {
let f1 =
FixedI64::saturating_from_integer(x) / FixedI64::saturating_from_integer(y);
let f2 = FixedI64::saturating_from_rational(x, y);
assert_eq!(f1.into_inner(), f2.into_inner());
}
let a = FixedI64::saturating_from_rational(2, 5);
let b = a.saturating_mul(FixedI64::saturating_from_integer(x));
let n = b.into_inner() as i128;
let m = 2i128 * x * FixedI64::accuracy() as i128 / 5i128;
assert_eq!(n, m);
if x != 0 {
assert_eq!(a, b / FixedI64::saturating_from_integer(x));
}
let r = a.reciprocal().unwrap().reciprocal().unwrap();
assert_eq!(a, r);
let a = FixedI64::saturating_from_integer(x);
let b = FixedI64::saturating_from_integer(y);
let c = FixedI64::saturating_from_integer(x.saturating_add(y));
assert_eq!(a.saturating_add(b), c);
let a = FixedI64::saturating_from_integer(x);
let b = FixedI64::saturating_from_integer(y);
let c = FixedI64::saturating_from_integer(x.saturating_sub(y));
assert_eq!(a.saturating_sub(b), c);
let a = FixedI64::saturating_from_rational(2, 5);
let b = a.saturating_mul_acc_int(x);
let xx = FixedI64::saturating_from_integer(x);
let d = a.saturating_mul(xx).saturating_add(xx).into_inner() as i128 /
FixedI64::accuracy() as i128;
assert_eq!(b, d);
});
}
}