Skip to content

[31/N] Add unit tests for BruteForce, BoyerMoore, KMP, RabinKarp, and LCS pattern matching algorithms - #122

Open
karkir0003 wants to merge 31 commits into
csvistool:masterfrom
karkir0003:karthik/kar-38-add-unit-tests-for-bruteforce-boyermoore-kmp-rabinkarp-and-lcs
Open

karkir0003 wants to merge 31 commits into
csvistool:masterfrom
karkir0003:karthik/kar-38-add-unit-tests-for-bruteforce-boyermoore-kmp-rabinkarp-and-lcs

Conversation

@karkir0003

@karkir0003 karkir0003 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🥞 Stack

  1. ⬅️ [1/N] Update CI to run frontend unit tests #91 (Add test infrastructure and Jest setup)
  2. ⬅️ [2/N] Configure React Testing Library and Setup Tests #92 (Add unit tests for Footer, Header, and Blob components)
  3. ⬅️ [3/N] Add unit tests for SideButton component #94 (Add unit tests for AlgorithmNotFound404 component)
  4. ⬅️ [4/N] Add unit tests for SearchFilter component #95 (Add unit tests for Pseudocode component)
  5. ⬅️ [5/N] Add unit tests for Header and Footer components #96 (Add unit tests for AlgoSection component)
  6. ⬅️ [6/N] Add unit tests for Blob mascot component #97 (Add unit tests for ModalSidebarSectionTab component)
  7. ⬅️ [7/N] Add unit tests for AboutScreen screen #98 (Add unit tests for BigOModal component)
  8. ⬅️ [8/N] Add integration tests for HomeScreen screen #99 (Add unit tests for InfoModals component)
  9. ⬅️ [9/N] Add unit tests for AlgorithmNotFound404 component #100 (Add unit tests for SideButton component)
  10. ⬅️ [10/N] Add integration tests for AlgoScreen screen #101 (Add unit tests for SearchFilter component)
  11. ⬅️ [11/N] Add unit tests for ModalSidebarSectionTab component #102 (Add unit tests for HomeScreen)
  12. ⬅️ [12/N] Add unit tests for BigOModal component #103 (Add unit tests for AboutScreen)
  13. ⬅️ [13/N] Add unit tests for Pseudocode component #104 (Add unit tests for AlgoScreen)
  14. ⬅️ [14/N] Add unit and integration tests for AlgoSection component #105 (Add unit tests for AlgoList registry)
  15. ⬅️ [15/N] Add unit and integration tests for root App component #106 (Add unit and integration tests for root App component)
  16. ⬅️ [16/N] Add unit tests for animation events and undo functions #107 (Add unit tests for animation events and undo functions)
  17. ⬅️ [17/N] Add unit tests for AnimatedObject, AnimatedCircle, and AnimatedHighlightCircle #108 (Add unit tests for AnimatedObject, AnimatedCircle, and AnimatedHighlightCircle)
  18. ⬅️ [18/N] Add unit tests for AnimatedRectangle, AnimatedLabel, and AnimatedLine #109 (Add unit tests for AnimatedRectangle, AnimatedLabel, and AnimatedLine)
  19. ⬅️ [19/N] Add unit tests for AnimatedLinkedListNode, AnimatedDoublyLinkedListNode, and AnimatedCircularlyLinkedListNode #110 (Add unit tests for AnimatedLinkedListNode, AnimatedDoublyLinkedListNode, and AnimatedCircularlyLinkedListNode)
  20. ⬅️ [20/N] Add unit tests for AnimatedBTreeNode and AnimatedSkipListNode #111 (Add unit tests for AnimatedBTreeNode and AnimatedSkipListNode)
  21. ⬅️ [21/N] Add unit tests for ObjectManager #112 (Add unit tests for ObjectManager)
  22. ⬅️ [22/N] Add unit tests for AnimationMain #113 (Add unit tests for AnimationMain)
  23. ⬅️ [23/N] Add unit tests for algo util helpers (PriorityQueue, SkipListHeads, GraphValues) #114 (Add unit tests for algo util helpers (PriorityQueue, SkipListHeads, GraphValues))
  24. ⬅️ [24/N] Add unit tests for base Algorithm class and control bar helpers #115 (Add unit tests for base Algorithm class and control bar helpers)
  25. ⬅️ [25/N] Add unit tests for ArrayList algorithm #116 (Add unit tests for ArrayList algorithm)
  26. ⬅️ [26/N] Add unit tests for LinkedList, DoublyLinkedList, and CircularlyLinkedList algorithms #117 (Add unit tests for LinkedList, DoublyLinkedList, and CircularlyLinkedList algorithms)
  27. ⬅️ [27/N] Add unit tests for Stack, Queue, and Deque algorithms (Array and LL variants) #118 (Add unit tests for Stack, Queue, and Deque algorithms (Array and LL variants))
  28. ⬅️ [28/N] Add unit tests for BST, AVL, Heap, and SplayTree algorithms #119 (Add unit tests for BST, AVL, Heap, and SplayTree algorithms)
  29. ⬅️ [29/N] Add unit tests for BTree, TreeMap, SkipList, and DisjointSet algorithms #120 (Add unit tests for BTree, TreeMap, SkipList, and DisjointSet algorithms)
  30. ⬅️ [30/N] Add unit tests for Hash, OpenHash, ClosedHash, and NonLinearProbing algorithms #121 (Add unit tests for Hash, OpenHash, ClosedHash, and NonLinearProbing algorithms)
  31. 👉 #CURRENT — Add unit tests for BruteForce, BoyerMoore, KMP, RabinKarp, and LCS pattern matching algorithms (this PR)
  32. ➡️ [32/N] Add unit tests for BubbleSort, CocktailSort, SelectionSort, InsertionSort, MergeSort, Quicksort, Quickselect, and HeapSort algorithms #123 (Add unit tests for BubbleSort, CocktailSort, SelectionSort, InsertionSort, MergeSort, Quicksort, Quickselect, and HeapSort algorithms)

Addresses #93

Context

Adds comprehensive unit test coverage for the pattern matching and string algorithms visualizers:

  • BruteForce.js: Naive brute-force string search comparing text against pattern character-by-character, updating comparison counts, matrix visualization, and dynamically calculating cell sizes.
  • BoyerMoore.js: Boyer-Moore pattern matching with Last Occurrence Table (LOT), right-to-left character comparison scans, wildcard shifts, and optional Galil Rule optimization with failure table period skipping.
  • KMP.js: Knuth-Morris-Pratt string matching with Failure Table preprocessing, prefix-suffix border alignment shifts on mismatch, and left-to-right scanning.
  • RabinKarp.js: Rabin-Karp string matching with polynomial rolling hash computation, base configuration (changeBase), spurious hit character-by-character resolution, and match verification.
  • LCS.js: Longest Common Subsequence dynamic programming visualizer with 2D score matrix construction, diagonal matching increments, mismatch maximum propagation, and backtracking reconstruction.

Changes Made

  • Introduced src/algo/__tests__/BruteForce.test.js:
    • Input controls, text/pattern fields, find callback, and keyboard handlers.
    • Validation for empty text/pattern and pattern longer than text.
    • Full match, partial match, and mismatch animations with pointer movements.
    • Dynamic cell size computation based on row count thresholds.
    • Example dropdown selection (predefined and Random string generation).
    • Clear and URL parameter initialization.
  • Introduced src/algo/__tests__/BoyerMoore.test.js:
    • Control registration, Last Occurrence Table build button, and Galil Rule toggle checkbox.
    • LOT construction with character mapping and wildcard * fallback (-1).
    • Search execution without Galil Rule (standard LOT shifts) and with Galil Rule enabled (skipping period).
    • Calculation of maximum rows and period calculations.
    • URL parameter parsing (galil, text, pattern).
  • Introduced src/algo/__tests__/KMP.test.js:
    • Control registration, Failure Table standalone build button.
    • Failure table computation testing prefix matching border values.
    • Shift alignment logic on mismatch (distinguishing j === 0 from j > 0 with failureTable[j - 1]).
    • Search hits, comparison count updates, and clearing/resetting state.
  • Introduced src/algo/__tests__/RabinKarp.test.js:
    • Control registration, customizable base constant field, and base change action.
    • Input sanitization (stripping non-alphabetic characters and lowercasing).
    • Rolling hash formula computation and verification.
    • Spurious collision handling (matching hash but mismatching characters).
    • URL parameter parsing (base, text, pattern).
  • Introduced src/algo/__tests__/LCS.test.js:
    • S1 and S2 inputs, Run button, Random pair generator, and Clear button.
    • DP matrix construction with base cases (0-row and 0-column).
    • Matching diagonal increment animation and mismatch max selection.
    • Backtracking through 2D table to reconstruct the LCS sequence.
    • URL parameter parsing (s1, s2).

Test Plan

  • Ran npm test -- --watchAll=false (all 5 new test suites pass, 69 unit tests passing; 60 suites, 679 tests passing repository-wide).
  • Ran npm run lint and npm run prettier (0 errors, 0 warnings).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant