Skip to content

Commit 02ab7fe

Browse files
committed
Add parameterized tests for Euler totient with 100% coverage / after echo
1 parent ebcb859 commit 02ab7fe

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/number_theory/euler_totient.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,46 @@ mod tests {
3636
#[test]
3737
fn test_euler_totient_comprehensive() {
3838
let test_cases = vec![
39-
// Edges cases
39+
// Edges cases
4040
(1, 1),
41-
4241
// small numbers
43-
(2, 1),(3, 2),(4, 2),
44-
(5, 4),(6, 2),
45-
42+
(2, 1),
43+
(3, 2),
44+
(4, 2),
45+
(5, 4),
46+
(6, 2),
4647
//Prime numbers (φ(p) = p - 1)
47-
(7, 6),(11, 10),(13, 12),
48-
(17, 16),(19,18),
49-
48+
(7, 6),
49+
(11, 10),
50+
(13, 12),
51+
(17, 16),
52+
(19, 18),
5053
// Prime powers (φ(p^k) = p^(k-1) * (p-1))
5154
(8, 4), // 2^3
52-
(9, 6), // 3^2
55+
(9, 6), // 3^2
5356
(16, 8), // 2^4
5457
(25, 20), // 5^2
5558
(27, 18), // 3^3
5659
(32, 16), // 2^5
57-
5860
// Composite numbers
59-
(10, 4), // 2 * 5
60-
(12, 4), // 2^2 * 3
61-
(15, 8), // 3 * 5
62-
(18, 6), // 2 * 3^2
63-
(20, 8), // 2^2 * 5
64-
(30, 8), // 2 * 3 * 5
65-
// Large numbers
66-
(50, 20), // 2 * 5^2
67-
(100, 40),// 2^2 * 5^2
68-
(1000, 400) // 2^3 * 5^3
61+
(10, 4), // 2 * 5
62+
(12, 4), // 2^2 * 3
63+
(15, 8), // 3 * 5
64+
(18, 6), // 2 * 3^2
65+
(20, 8), // 2^2 * 5
66+
(30, 8), // 2 * 3 * 5
67+
// Large numbers
68+
(50, 20), // 2 * 5^2
69+
(100, 40), // 2^2 * 5^2
70+
(1000, 400), // 2^3 * 5^3
6971
];
70-
72+
7173
for (input, expected) in test_cases {
7274
assert_eq!(
73-
euler_totient(input),
74-
expected,
75-
"φ({}) should be {}",
76-
input,
75+
euler_totient(input),
76+
expected,
77+
"φ({}) should be {}",
78+
input,
7779
expected
7880
);
7981
}
@@ -89,7 +91,7 @@ mod tests {
8991
(77, 60), // 7 * 11 (ensures the final `if num > 1` branch)
9092
(128, 64), // Large power of 2
9193
];
92-
94+
9395
for (input, expected) in edge_cases {
9496
assert_eq!(euler_totient(input), expected);
9597
}

0 commit comments

Comments
 (0)