Skip to content

Commit 8d44461

Browse files
author
Mrinal Chauhan
committed
feat : added find majority element in array using Moore's Voting Algorithm test file
1 parent a7928f5 commit 8d44461

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {MooreVotingAlgorithm} from "../MooreVotingAlgorithm";
2+
describe('Moore Voting Algorithm', () => {
3+
it.each([
4+
[[1, 1, 2, 1, 3, 1, 1], 1], // Majority element 1
5+
[[1, 2, 3, 4], null], // No majority element
6+
[[2, 2, 2, 2, 5, 5, 5, 2], 2], // Majority element 2
7+
[[], null], // Empty array, no majority
8+
[[3], 3] // Single element, it's the majority
9+
])('returns %j when given %j', (array, expected) => {
10+
expect(MooreVotingAlgorithm(array)).toEqual(expected);
11+
});
12+
});

0 commit comments

Comments
 (0)