Skip to content

Commit b4846f4

Browse files
committed
std: partialeq tests for math types
1 parent addbd3f commit b4846f4

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

packages/std/src/math/decimal.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,4 +1942,24 @@ mod tests {
19421942
Err(RoundUpOverflowError { .. })
19431943
));
19441944
}
1945+
1946+
#[test]
1947+
fn decimal_partial_eq() {
1948+
let test_cases = [
1949+
("1", "1", true),
1950+
("0.5", "0.5", true),
1951+
("0.5", "0.51", false),
1952+
("0", "0.00000", true),
1953+
]
1954+
.into_iter()
1955+
.map(|(lhs, rhs, expected)| (dec(lhs), dec(rhs), expected));
1956+
1957+
#[allow(clippy::op_ref)]
1958+
for (lhs, rhs, expected) in test_cases {
1959+
assert_eq!(lhs == rhs, expected);
1960+
assert_eq!(&lhs == rhs, expected);
1961+
assert_eq!(lhs == &rhs, expected);
1962+
assert_eq!(&lhs == &rhs, expected);
1963+
}
1964+
}
19451965
}

packages/std/src/math/decimal256.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,4 +2089,24 @@ mod tests {
20892089
);
20902090
assert_eq!(Decimal256::MAX.checked_ceil(), Err(RoundUpOverflowError));
20912091
}
2092+
2093+
#[test]
2094+
fn decimal256_partial_eq() {
2095+
let test_cases = [
2096+
("1", "1", true),
2097+
("0.5", "0.5", true),
2098+
("0.5", "0.51", false),
2099+
("0", "0.00000", true),
2100+
]
2101+
.into_iter()
2102+
.map(|(lhs, rhs, expected)| (dec(lhs), dec(rhs), expected));
2103+
2104+
#[allow(clippy::op_ref)]
2105+
for (lhs, rhs, expected) in test_cases {
2106+
assert_eq!(lhs == rhs, expected);
2107+
assert_eq!(&lhs == rhs, expected);
2108+
assert_eq!(lhs == &rhs, expected);
2109+
assert_eq!(&lhs == &rhs, expected);
2110+
}
2111+
}
20922112
}

packages/std/src/math/uint128.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,4 +994,19 @@ mod tests {
994994
assert_eq!(a.abs_diff(b), expected);
995995
assert_eq!(b.abs_diff(a), expected);
996996
}
997+
998+
#[test]
999+
fn uint128_partial_eq() {
1000+
let test_cases = [(1, 1, true), (42, 42, true), (42, 24, false), (0, 0, true)]
1001+
.into_iter()
1002+
.map(|(lhs, rhs, expected)| (Uint128::new(lhs), Uint128::new(rhs), expected));
1003+
1004+
#[allow(clippy::op_ref)]
1005+
for (lhs, rhs, expected) in test_cases {
1006+
assert_eq!(lhs == rhs, expected);
1007+
assert_eq!(&lhs == rhs, expected);
1008+
assert_eq!(lhs == &rhs, expected);
1009+
assert_eq!(&lhs == &rhs, expected);
1010+
}
1011+
}
9971012
}

packages/std/src/math/uint256.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,4 +1545,25 @@ mod tests {
15451545
assert_eq!(a.abs_diff(b), expected);
15461546
assert_eq!(b.abs_diff(a), expected);
15471547
}
1548+
1549+
#[test]
1550+
fn uint256_partial_eq() {
1551+
let test_cases = [(1, 1, true), (42, 42, true), (42, 24, false), (0, 0, true)]
1552+
.into_iter()
1553+
.map(|(lhs, rhs, expected)| {
1554+
(
1555+
Uint256::from(lhs as u64),
1556+
Uint256::from(rhs as u64),
1557+
expected,
1558+
)
1559+
});
1560+
1561+
#[allow(clippy::op_ref)]
1562+
for (lhs, rhs, expected) in test_cases {
1563+
assert_eq!(lhs == rhs, expected);
1564+
assert_eq!(&lhs == rhs, expected);
1565+
assert_eq!(lhs == &rhs, expected);
1566+
assert_eq!(&lhs == &rhs, expected);
1567+
}
1568+
}
15481569
}

packages/std/src/math/uint512.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,4 +1180,25 @@ mod tests {
11801180
assert_eq!(a.abs_diff(b), expected);
11811181
assert_eq!(b.abs_diff(a), expected);
11821182
}
1183+
1184+
#[test]
1185+
fn uint512_partial_eq() {
1186+
let test_cases = [(1, 1, true), (42, 42, true), (42, 24, false), (0, 0, true)]
1187+
.into_iter()
1188+
.map(|(lhs, rhs, expected)| {
1189+
(
1190+
Uint512::from(lhs as u64),
1191+
Uint512::from(rhs as u64),
1192+
expected,
1193+
)
1194+
});
1195+
1196+
#[allow(clippy::op_ref)]
1197+
for (lhs, rhs, expected) in test_cases {
1198+
assert_eq!(lhs == rhs, expected);
1199+
assert_eq!(&lhs == rhs, expected);
1200+
assert_eq!(lhs == &rhs, expected);
1201+
assert_eq!(&lhs == &rhs, expected);
1202+
}
1203+
}
11831204
}

packages/std/src/math/uint64.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,4 +907,19 @@ mod tests {
907907
assert_eq!(a.abs_diff(b), expected);
908908
assert_eq!(b.abs_diff(a), expected);
909909
}
910+
911+
#[test]
912+
fn uint64_partial_eq() {
913+
let test_cases = [(1, 1, true), (42, 42, true), (42, 24, false), (0, 0, true)]
914+
.into_iter()
915+
.map(|(lhs, rhs, expected)| (Uint64::new(lhs), Uint64::new(rhs), expected));
916+
917+
#[allow(clippy::op_ref)]
918+
for (lhs, rhs, expected) in test_cases {
919+
assert_eq!(lhs == rhs, expected);
920+
assert_eq!(&lhs == rhs, expected);
921+
assert_eq!(lhs == &rhs, expected);
922+
assert_eq!(&lhs == &rhs, expected);
923+
}
924+
}
910925
}

0 commit comments

Comments
 (0)