100-exercises-to-learn-rust/exercises/04_traits/09_assoc_vs_generic/src/lib.rs

26 lines
596 B
Rust
Raw Normal View History

2024-05-13 04:21:03 +08:00
// TODO: Define a new trait, `Power`, that has a method `power` that raises `self` to the power of `n`.
// The trait definition and its implementations should be enough to get the tests to compile and pass.
#[cfg(test)]
mod tests {
use super::Power;
#[test]
fn test_power_u16() {
let x: u32 = 2_u32.power(3u16);
assert_eq!(x, 8);
}
#[test]
fn test_power_u32() {
let x: u32 = 2_u32.power(3u32);
assert_eq!(x, 8);
}
#[test]
fn test_power_ref_u32() {
let x: u32 = 2_u32.power(&3u32);
assert_eq!(x, 8);
}
}