100 exercises to learn Rust
This commit is contained in:
4
exercises/04_traits/09_assoc_vs_generic/Cargo.toml
Normal file
4
exercises/04_traits/09_assoc_vs_generic/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "assoc_vs_generic"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
25
exercises/04_traits/09_assoc_vs_generic/src/lib.rs
Normal file
25
exercises/04_traits/09_assoc_vs_generic/src/lib.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user