Skip to content

Commit 2abfaa9

Browse files
author
WinterPancake
committed
Added better explanation to functionality of rising_factorial.rs as well as comments for the all of the test cases. Also added comments to test cases for simplicial_polytopic_number.rs.
1 parent 2da705f commit 2abfaa9

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/math/rising_factorial.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::ops::Mul;
77
// https://mathworld.wolfram.com/RisingFactorial.html
88
// https://en.wikipedia.org/wiki/Falling_and_rising_factorials
99
//
10-
// Returns the nth rising factorial.
10+
// Returns the nth rising factorial. Which is calculated by giving the nth term and then
11+
// substituting our desired x; i.e. rising_factorial(4, 5) would give 4 * 5 * 6 * 7 * 8 = 6720.
1112
pub fn rising_factorial(x: u64, n: u64) -> u64 {
1213
let mut result = x;
1314
for i in 1..n {
@@ -23,11 +24,11 @@ mod tests {
2324

2425
#[test]
2526
fn test_rising_factorial() {
26-
assert_eq!(rising_factorial(1, 0), 1);
27-
assert_eq!(rising_factorial(1, 1), 1);
28-
assert_eq!(rising_factorial(2, 1), 2);
29-
assert_eq!(rising_factorial(1, 2), 2); // 1 * 2
30-
assert_eq!(rising_factorial(2, 2), 6); // 2 * 3
31-
assert_eq!(rising_factorial(3, 3), 60); // 3 * 4 * 5
27+
assert_eq!(rising_factorial(1, 0), 1); // 0! = 1
28+
assert_eq!(rising_factorial(1, 1), 1); // 1 = 1
29+
assert_eq!(rising_factorial(2, 1), 2); // 2 = 2
30+
assert_eq!(rising_factorial(1, 2), 2); // 1 * 2 = 2
31+
assert_eq!(rising_factorial(2, 2), 6); // 2 * 3 = 6
32+
assert_eq!(rising_factorial(3, 3), 60); // 3 * 4 * 5 = 60
3233
}
3334
}

src/math/simplicial_polytopic_number.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ mod tests {
3636
}
3737

3838
test_simplicial_polytopic_number! {
39-
input_0: ((1, 1), 1),
40-
input_1: ((2, 1), 2),
41-
input_2: ((2, 2), 3),
42-
input_3: ((3, 3), 10),
43-
input_4: ((2, 4), 5),
44-
input_5: ((5, 5), 126),
45-
input_6: ((9, 6), 3003),
46-
input_7: ((6, 10), 3003),
39+
input_0: ((1, 1), 1), // 1st natural number = 1
40+
input_1: ((2, 1), 2), // 2nd natural number = 2
41+
input_2: ((2, 2), 3), // 2nd triangular number = 3
42+
input_3: ((3, 3), 10), // 3rd tetrahedral number = 10
43+
input_4: ((2, 4), 5), // 2nd pentatope number = 5
44+
input_5: ((5, 5), 126), // 5th 5_simplex = 126
45+
input_6: ((9, 6), 3003), // 9th 6_simplex = 3003
46+
input_7: ((6, 10), 3003), // 6th 10_simplex = 3003
4747
}
4848
}

0 commit comments

Comments
 (0)