1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
pub fn factorial(a: i32) -> i32 {
    if a == 1 {
        return 1;
    }
    factorial(a - 1) * a
}

#[cfg(test)]
mod tests {
    // Note this useful idiom: importing names from outer (for mod tests) scope.
    use super::*;

    #[test]
    fn test_factorial() {
        assert_eq!(factorial(5), 120);
    }
}