initial commit
This commit is contained in:
4
exercises/04_traits/01_trait/Cargo.toml
Normal file
4
exercises/04_traits/01_trait/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "trait_"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
23
exercises/04_traits/01_trait/src/lib.rs
Normal file
23
exercises/04_traits/01_trait/src/lib.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
// Define a trait named `IsEven` that has a method `is_even` that returns a `true` if `self` is
|
||||
// even, otherwise `false`.
|
||||
//
|
||||
// Then implement the trait for `u32` and `i32`.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_u32_is_even() {
|
||||
assert!(42u32.is_even());
|
||||
assert!(!43u32.is_even());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_is_even() {
|
||||
assert!(42i32.is_even());
|
||||
assert!(!43i32.is_even());
|
||||
assert!(0i32.is_even());
|
||||
assert!(!(-1i32).is_even());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user