26 lines
596 B
Rust
26 lines
596 B
Rust
|
// 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);
|
||
|
}
|
||
|
}
|