Skip to content

Commit 74b9de4

Browse files
committed
Add test for all midpoint expectations
1 parent 00444ba commit 74b9de4

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎library/core/tests/num/midpoint.rs‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Test the following expectations:
2+
//! - midpoint(a, b) == (a + b) / 2
3+
//! - midpoint(a, b) == midpoint(b, a)
4+
//! - midpoint(-a, -b) == -midpoint(a, b)
5+
6+
#[test]
7+
#[cfg(not(miri))]
8+
fnmidpoint_obvious_impl_i8(){
9+
for a in i8::MIN..=i8::MAX{
10+
for b in i8::MIN..=i8::MAX{
11+
assert_eq!(i8::midpoint(a, b),((a asi16 + b asi16) / 2)asi8);
12+
}
13+
}
14+
}
15+
16+
#[test]
17+
#[cfg(not(miri))]
18+
fnmidpoint_obvious_impl_u8(){
19+
for a in u8::MIN..=u8::MAX{
20+
for b in u8::MIN..=u8::MAX{
21+
assert_eq!(u8::midpoint(a, b),((a asu16 + b asu16) / 2)asu8);
22+
}
23+
}
24+
}
25+
26+
#[test]
27+
#[cfg(not(miri))]
28+
fnmidpoint_order_expectation_i8(){
29+
for a in i8::MIN..=i8::MAX{
30+
for b in i8::MIN..=i8::MAX{
31+
assert_eq!(i8::midpoint(a, b),i8::midpoint(b, a));
32+
}
33+
}
34+
}
35+
36+
#[test]
37+
#[cfg(not(miri))]
38+
fnmidpoint_order_expectation_u8(){
39+
for a in u8::MIN..=u8::MAX{
40+
for b in u8::MIN..=u8::MAX{
41+
assert_eq!(u8::midpoint(a, b),u8::midpoint(b, a));
42+
}
43+
}
44+
}
45+
46+
#[test]
47+
#[cfg(not(miri))]
48+
fnmidpoint_negative_expectation(){
49+
for a in0..=i8::MAX{
50+
for b in0..=i8::MAX{
51+
assert_eq!(i8::midpoint(-a, -b), -i8::midpoint(a, b));
52+
}
53+
}
54+
}

‎library/core/tests/num/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod dec2flt;
2828
mod flt2dec;
2929
mod int_log;
3030
mod int_sqrt;
31+
mod midpoint;
3132
mod ops;
3233
mod wrapping;
3334

0 commit comments

Comments
 (0)