mirror of
https://github.com/mainmatter/100-exercises-to-learn-rust
synced 2024-12-25 21:58:26 +01:00
Change if-else exercise to require an if-else (#238)
This commit is contained in:
parent
fb19005d5f
commit
36f6375c20
1 changed files with 18 additions and 6 deletions
|
@ -1,24 +1,36 @@
|
||||||
/// Return `true` if `n` is even, `false` otherwise.
|
/// Return `12` if `n` is even,
|
||||||
fn is_even(n: u32) -> bool {
|
/// `13` if `n` is divisible by `3`,
|
||||||
|
/// `17` otherwise.
|
||||||
|
fn magic_number(n: u32) -> u32 {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::is_even;
|
use crate::magic_number;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one() {
|
fn one() {
|
||||||
assert!(!is_even(1));
|
assert_eq!(magic_number(1), 17);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn two() {
|
fn two() {
|
||||||
assert!(is_even(2));
|
assert_eq!(magic_number(2), 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn six() {
|
||||||
|
assert_eq!(magic_number(6), 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nine() {
|
||||||
|
assert_eq!(magic_number(9), 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn high() {
|
fn high() {
|
||||||
assert!(!is_even(231));
|
assert_eq!(magic_number(233), 17);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue