Skip to content

Commit f521427

Browse files
committed
Add overflowing addition tests
1 parent e949f66 commit f521427

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

testcrate/tests/addsub.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use compiler_builtins::int::addsub::{
2+
__rust_i128_add, __rust_i128_addo, __rust_i128_sub, __rust_i128_subo, __rust_u128_add,
3+
__rust_u128_addo, __rust_u128_sub, __rust_u128_subo,
4+
};
5+
6+
#[test]
7+
fn addsub_test() {
8+
testcrate::fuzz_2(1000, |x: i128, y: i128| {
9+
let add0 = x.wrapping_add(y);
10+
let add1 = __rust_i128_add(x, y);
11+
if add0 != add1 {
12+
panic!(
13+
"__rust_i128_add({}, {}): expected: {}, found: {}",
14+
x, y, add0, add1
15+
);
16+
}
17+
});
18+
testcrate::fuzz_2(1000, |x: i128, y: i128| {
19+
let (add0, o0) = x.overflowing_add(y);
20+
let (add1, o1) = __rust_i128_addo(x, y);
21+
if add0 != add1 || o0 != o1 {
22+
panic!(
23+
"__rust_i128_addo({}, {}): expected: {} (oflow = {}), found: {} (oflow = {})",
24+
x, y, add0, o0, add1, o1
25+
);
26+
}
27+
});
28+
testcrate::fuzz_2(1000, |x: i128, y: i128| {
29+
let sub0 = x.wrapping_sub(y);
30+
let sub1 = __rust_i128_sub(x, y);
31+
if sub0 != sub1 {
32+
panic!(
33+
"__rust_i128_sub({}, {}): expected: {}, found: {}",
34+
x, y, sub0, sub1
35+
);
36+
}
37+
});
38+
testcrate::fuzz_2(1000, |x: i128, y: i128| {
39+
let (sub0, o0) = x.overflowing_sub(y);
40+
let (sub1, o1) = __rust_i128_subo(x, y);
41+
if sub0 != sub1 || o0 != o1 {
42+
panic!(
43+
"__rust_i128_subo({}, {}): expected: {} (oflow = {}), found: {} (oflow = {})",
44+
x, y, sub0, o0, sub1, o1
45+
);
46+
}
47+
});
48+
testcrate::fuzz_2(1000, |x: u128, y: u128| {
49+
let add0 = x.wrapping_add(y);
50+
let add1 = __rust_u128_add(x, y);
51+
if add0 != add1 {
52+
panic!(
53+
"__rust_u128_add({}, {}): expected: {}, found: {}",
54+
x, y, add0, add1
55+
);
56+
}
57+
});
58+
testcrate::fuzz_2(1000, |x: u128, y: u128| {
59+
let (add0, o0) = x.overflowing_add(y);
60+
let (add1, o1) = __rust_u128_addo(x, y);
61+
if add0 != add1 || o0 != o1 {
62+
panic!(
63+
"__rust_u128_addo({}, {}): expected: {} (oflow = {}), found: {} (oflow = {})",
64+
x, y, add0, o0, add1, o1
65+
);
66+
}
67+
});
68+
testcrate::fuzz_2(1000, |x: u128, y: u128| {
69+
let sub0 = x.wrapping_sub(y);
70+
let sub1 = __rust_u128_sub(x, y);
71+
if sub0 != sub1 {
72+
panic!(
73+
"__rust_u128_sub({}, {}): expected: {}, found: {}",
74+
x, y, sub0, sub1
75+
);
76+
}
77+
});
78+
testcrate::fuzz_2(1000, |x: u128, y: u128| {
79+
let (sub0, o0) = x.overflowing_sub(y);
80+
let (sub1, o1) = __rust_u128_subo(x, y);
81+
if sub0 != sub1 || o0 != o1 {
82+
panic!(
83+
"__rust_u128_subo({}, {}): expected: {} (oflow = {}), found: {} (oflow = {})",
84+
x, y, sub0, o0, sub1, o1
85+
);
86+
}
87+
});
88+
}

0 commit comments

Comments
 (0)