Skip to content

[32/N] Add unit tests for BubbleSort, CocktailSort, SelectionSort, InsertionSort, MergeSort, Quicksort, Quickselect, and HeapSort algorithms - #123

Open
karkir0003 wants to merge 32 commits into
csvistool:masterfrom
karkir0003:karthik/kar-39-add-unit-tests-for-comparison-sorting-algorithms
Open

karkir0003 wants to merge 32 commits into
csvistool:masterfrom
karkir0003:karthik/kar-39-add-unit-tests-for-comparison-sorting-algorithms

Conversation

@karkir0003

@karkir0003 karkir0003 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

PR 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 Header, Footer, and Blob components)
  3. ⬅️ [3/N] Add unit tests for SideButton component #94 (Add unit tests for HomeScreen components (SideButton, SearchFilter))
  4. ⬅️ [4/N] Add unit tests for SearchFilter component #95 (Add unit tests for AlgoScreen components (AlgoSection, Pseudocode, ModalSidebarSectionTab))
  5. ⬅️ [6/N] Add unit tests for Blob mascot component #97 (Add unit tests for modals (BigOModal, InfoModals))
  6. ⬅️ [5/N] Add unit tests for Header and Footer components #96 (Add unit tests for AlgorithmNotFound404 component)
  7. ⬅️ [7/N] Add unit tests for AboutScreen screen #98 (Add unit tests for HomeScreen page)
  8. ⬅️ [8/N] Add integration tests for HomeScreen screen #99 (Add unit tests for AboutScreen page)
  9. ⬅️ [9/N] Add unit tests for AlgorithmNotFound404 component #100 (Add unit tests for AlgoScreen page)
  10. ⬅️ [10/N] Add integration tests for AlgoScreen screen #101 (Add unit tests for App root component and routes)
  11. ⬅️ [11/N] Add unit tests for ModalSidebarSectionTab component #102 (Add test coverage workflow for CI)
  12. ⬅️ [12/N] Add unit tests for BigOModal component #103 (Add unit tests for CustomEvents animation utility)
  13. ⬅️ [13/N] Add unit tests for Pseudocode component #104 (Add unit tests for UndoFunctions animation utility)
  14. ⬅️ [14/N] Add unit and integration tests for AlgoSection component #105 (Add unit tests for AnimatedCircle animation primitive)
  15. ⬅️ [15/N] Add unit and integration tests for root App component #106 (Add unit tests for AnimatedHighlightCircle)
  16. ⬅️ [16/N] Add unit tests for animation events and undo functions #107 (Add unit tests for SingleAnimation)
  17. ⬅️ [17/N] Add unit tests for AnimatedObject, AnimatedCircle, and AnimatedHighlightCircle #108 (Add unit tests for AnimatedObject base class)
  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. ⬅️ [31/N] Add unit tests for BruteForce, BoyerMoore, KMP, RabinKarp, and LCS pattern matching algorithms #122 (Add unit tests for BruteForce, BoyerMoore, KMP, RabinKarp, and LCS pattern matching algorithms)
  32. 👉 #CURRENT — Add unit tests for BubbleSort, CocktailSort, SelectionSort, InsertionSort, MergeSort, Quicksort, Quickselect, and HeapSort algorithms (this PR)
  33. ➡️ [33/N] Add unit tests for LSDRadix, RadixSort, BogoSort, DropSort, FredSort, MiracleSort, and SleepSort algorithms #124 (Add unit tests for LSDRadix, RadixSort, BogoSort, DropSort, FredSort, MiracleSort, and SleepSort algorithms)

Addresses #93

Context

Adds comprehensive unit test coverage for comparison-based sorting algorithms and order-statistic selection visualizers:

  • BubbleSort.js: Standard bubble sort with adjacent comparisons, swap counter tracking, early termination pass check, and last-swap optimization toggle (toggleLastSwap).
  • CocktailSort.js: Bidirectional cocktail shaker sort with alternating forward and backward bubbling passes, dual last-swap boundary tracking, and early termination.
  • SelectionSort.js: In-place selection sort with minimum scanning, candidate element tracking, swap execution, and min/max variant selection callback (minCallback / maxCallback).
  • InsertionSort.js: Insertion sort with sorted partition expansion, element shifting, key insertion animation, and comparison/swap metric updates.
  • MergeSort.js: Recursive divide-and-conquer merge sort visualizer with sub-array block splitting, tree level hierarchy display, and merged array reconstruction.
  • Quicksort.js: Quicksort with pivot selection modes (Random, First, Last), two-pointer partition scanning, pivot placement, and recursive boundary sorting.
  • Quickselect.js: Quickselect order-statistic selection finding the k-th smallest element via partitioned pivot pruning, branch selection, and index target validation.
  • HeapSort.js: In-place heap sort combining binary heap tree visualization and array representation, bottom-up max-heap construction (siftDown), and extract-max sorting passes.

Changes Made

  • Introduced src/algo/__tests__/BubbleSort.test.js:
    • Control registration, sort button, preset values, random array generator, and clear actions.
    • Validation for array bounds (max 18 items), values > 999, and non-numeric inputs.
    • Comparison and swap counter increments, sorted element highlights, and early exit when sorted.
    • Last-swap optimization checkbox toggle and URL parameter parsing (lastSwap, data).
  • Introduced src/algo/__tests__/CocktailSort.test.js:
    • Forward and backward bubbling passes, sorted boundary markers, and comparison/swap counters.
    • Validation checks, preset population, and random array generation.
    • Last-swap optimization toggle and URL parameter initialization.
  • Introduced src/algo/__tests__/SelectionSort.test.js:
    • Control registration, validation (max 18 items, >999, non-numeric).
    • Min scanning pointer animations, swap execution, and counter tracking.
    • Min / Max variant selection callbacks and URL parameter parsing.
  • Introduced src/algo/__tests__/InsertionSort.test.js:
    • Validation checks, preset loading, and random list generator.
    • Shifting and insertion animation sequences, comparison/swap tracking, and URL parameter parsing.
  • Introduced src/algo/__tests__/MergeSort.test.js:
    • Validation (max 15 items, >999, non-numeric).
    • Sub-array splitting, recursive level placement, and merge reconstruction.
    • Preset examples, random generator, and URL parameter parsing.
  • Introduced src/algo/__tests__/Quicksort.test.js:
    • Partitioning with left/right scanning pointers, pivot swapping, and recursive call tracking.
    • Pivot selection dropdown options and validation checks.
    • Preset values, random generator, and URL parameter parsing.
  • Introduced src/algo/__tests__/Quickselect.test.js:
    • Input validation for array data and target k index boundaries.
    • run(list, k) execution with partition pruning directly to the target element.
    • Identification highlight of the k-th smallest element and URL parameter initialization (k, data).
  • Introduced src/algo/__tests__/HeapSort.test.js:
    • Validation (max 15 items, >999, non-numeric).
    • Dual array and binary heap tree node setup (heapArrayData, heapArrayID, heapTreeObj).
    • Max-heapify phase (siftDown), extract-max passes, and sorted tree animation.
    • Preset values, random generation, and URL parameter parsing.

Test Plan

  • Ran npm test -- --watchAll=false (all 8 new test suites pass, 86 unit tests passing; 68 suites, 765 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