35 lines
782 B
Rust
35 lines
782 B
Rust
#[cfg(test)]
|
|
mod tests {
|
|
use task_overflow_and_underflow::factorial;
|
|
|
|
#[test]
|
|
fn twentieth() {
|
|
// 20! is 2432902008176640000, which is too large to fit in a u32
|
|
// With the default dev profile, this will panic when you run `cargo test`
|
|
// We want it to wrap around instead
|
|
assert_eq!(factorial(20), 2_192_834_560);
|
|
// ☝️
|
|
// A large number literal using underscores to improve readability!
|
|
}
|
|
|
|
#[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);
|
|
}
|
|
}
|