initial commit
This commit is contained in:
10
exercises/02_basic_calculator/07_for/Cargo.toml
Normal file
10
exercises/02_basic_calculator/07_for/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "for_"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lints.rust]
|
||||
# We silence dead code warnings for the time being in order to reduce
|
||||
# compiler noise.
|
||||
# We'll re-enable them again once we explain how visibility works in Rust.
|
||||
dead_code = "allow"
|
||||
29
exercises/02_basic_calculator/07_for/src/lib.rs
Normal file
29
exercises/02_basic_calculator/07_for/src/lib.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// Rewrite the factorial function using a `for` loop.
|
||||
pub fn factorial(n: u32) -> u32 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::factorial;
|
||||
|
||||
#[test]
|
||||
fn first() {
|
||||
assert_eq!(factorial(0), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn second() {
|
||||
assert_eq!(factorial(1), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn third() {
|
||||
assert_eq!(factorial(2), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fifth() {
|
||||
assert_eq!(factorial(5), 120);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user