Skip to content

Instantly share code, notes, and snippets.

@masiarek
Last active November 26, 2024 12:41
Show Gist options
  • Save masiarek/3de96d0ec14d83f28e0b8b4740aa7ced to your computer and use it in GitHub Desktop.
Save masiarek/3de96d0ec14d83f28e0b8b4740aa7ced to your computer and use it in GitHub Desktop.
both work OK (compilation and cargo test)
fn main() {}
fn factorial(n: u64) -> u64 {
if n == 0 || n == 1 {
1
} else {
n * factorial(n - 1)
}
}
#[cfg(test)]
mod tests {
use crate::factorial;
#[test]
fn first() {
assert_eq!(factorial(0), 1);
}
#[test]
fn fifth() {
assert_eq!(factorial(4), 24);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment