pub mod calc1;
pub mod calc2;
#[cfg(test)]
mod tests {
use super::calc1::{add, sub};
use super::calc2::{multiply, rate};
#[test]
fn test_add_normal() {
assert_eq!(add(2, 2), 4);
}
#[test]
fn test_add_saturating() {
assert_eq!(add(u32::MAX, 1), u32::MAX);
}
#[test]
fn test_sub_normal() {
assert_eq!(sub(10, 5), 5);
}
#[test]
fn test_sub_underflow_returns_zero() {
assert_eq!(sub(5, 10), 0);
}
#[test]
fn test_multiply_normal() {
assert_eq!(multiply(10, 5), 50);
}
#[test]
fn test_multiply_by_zero() {
assert_eq!(multiply(10, 0), 0);
}
#[test]
fn test_multiply_overflow() {
assert_eq!(multiply(u32::MAX, 2), u32::MAX);
}
#[test]
fn test_rate_normal() {
assert_eq!(rate(10, 2), 5);
}
#[test]
fn test_rate_integer_truncation() {
assert_eq!(rate(10, 3), 3);
}
#[test]
fn test_rate_division_by_zero_returns_zero() {
assert_eq!(rate(10, 0), 0);
}
}