Skip to content

docs/tests: P4 — JSDoc + Big-O, Tower of Hanoi, missing tests, coverage improvements#259

Merged
loiane merged 1 commit into
mainfrom
loiane/p4-docs
Jul 2, 2026
Merged

docs/tests: P4 — JSDoc + Big-O, Tower of Hanoi, missing tests, coverage improvements#259
loiane merged 1 commit into
mainfrom
loiane/p4-docs

Conversation

@loiane

@loiane loiane commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • 335 tests, 22 suites — all passing
  • npx tsc --noEmit → 0 errors
  • Overall coverage: 94.3% stmts / 91.9% branches / 91.4% functions

Changes

New: src/04-stack/tower-of-hanoi.ts

Generic towerOfHanoi<T> migrated from JS, uses typed Stack<T>.

JSDoc + Big-O added to all public methods (~20 files)

Every public method in every core implementation file now has @param, @returns, and @complexity (Time + Space) annotations:
stack, queue, deque, linked-list, doubly-linked-list, circular-linked-list, set, hash-table, factorial, fibonacci, binary-search-tree, avl-tree, red-black-tree, fenwick-tree, segment-tree, comparator, heap, trie, graph, bfs, dfs, dijkstra, floyd-warshall, kruskal, prim, all array algorithm files

5 new test files

File Tests
04-stack/__test__/tower-of-hanoi.test.ts n=0..3, final state verification
05-queue-deque/__test__/algorithms.test.ts hotPotato game, isPalindrome
08-dictionary-hash/__test__/dictionary.test.ts Dictionary CRUD, forEach, object keys
08-dictionary-hash/__test__/hash-table-collision.test.ts SeparateChaining + LinearProbing (tests known bugs around get())
11-heap/__test__/heap-sort.test.ts HeapSort in-place, edge cases, custom comparator

Coverage improvements

File Before After
red-black-tree.ts 73.7% 89.6%
doubly-linked-list.ts 84.4% 98.9%
hash-table.ts 89.8% 98.9%

Low-coverage JS files (educational, expected)

  • hash-table-linear-probing.js (51%) — hash function has a known bug (returns function ref); tested the public interface
  • hash-table-separate-chaining.js (80%) — get() has a known bug (return inside forEach doesn't propagate); tested put/remove
  • linked-list_.js (49%) — legacy file used only as dependency for separate chaining; not a primary implementation
  • deque.js (61%) — CJS version, all real usage goes through deque.ts

…vements

TASK 1: Create Tower of Hanoi implementation
- Add src/04-stack/tower-of-hanoi.ts with generic towerOfHanoi<T> function
  using Stack<T> for source, auxiliary, and destination pegs

TASK 2: Add JSDoc with @param/@returns/@Complexity to all core files
- src/03-array/11-array-chunking.ts, 12-flatten-arrays.ts,
  13-remove-duplicates.ts, 14-array-rotation.ts (per-function JSDoc)
- src/04-stack/stack.ts, src/05-queue-deque/queue.ts, deque.ts
- src/06-linked-list/linked-list.ts, doubly-linked-list.ts,
  circular-linked-list.ts
- src/07-set/set.ts, src/08-dictionary-hash/hash-table.ts
- src/09-recursion/02-factorial.ts, 04-fibonacci.ts
- src/10-tree/binary-search-tree.ts, avl-tree.ts, red-black-tree.ts,
  fenwick-tree.ts, segment-tree.ts, comparator.ts, compare.ts
- src/11-heap/heap.ts, src/12-trie/trie.ts
- src/13-graph/graph.ts, bfs.ts, dfs.ts, dijkstra.ts, floyd-warshall.ts,
  kruskal.ts, prim.ts

TASK 3: Create new test files
- src/04-stack/__test__/tower-of-hanoi.test.ts
- src/05-queue-deque/__test__/algorithms.test.ts (hotPotato + isPalindrome)
- src/08-dictionary-hash/__test__/dictionary.test.ts
- src/08-dictionary-hash/__test__/hash-table-collision.test.ts
- src/11-heap/__test__/heap-sort.test.ts

TASK 4: Improve coverage on existing test files
- src/06-linked-list/__test__/doubly-linked-list.test.ts: add clear(),
  inverseToString(), reverse(), RangeError on invalid removeAt, object types
- src/08-dictionary-hash/__test__/hash-table.test.ts: add null key remove,
  multi-entry toString coverage
- src/10-tree/__test__/binary-search-tree.test.ts: add RBT rotation
  sequences [1,2,3], [3,2,1], [1,3,2]; remove leaf; remove nonexistent

Bug fixes (prerequisite for tests):
- Fix avl-tree.ts insert() body was empty after JSDoc addition
- Fix linked-list.ts duplicate code block after export statement
- Fix palindrome-checker.js: use require('./deque.js') to avoid ts-jest
  resolving to deque.ts default export
- Fix comparator.js: use require('./compare.js') to avoid ts-jest
  resolving to compare.ts named export (caused wrong comparison results)
- Fix heap-sort.js: use require('../10-tree/comparator.js') for same reason
- Add module.exports to hot-potato.js, palindrome-checker.js,
  hash-table-separate-chaining.js, hash-table-linear-probing.js

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@loiane loiane merged commit e8ee8f9 into main Jul 2, 2026
1 check passed
@loiane loiane deleted the loiane/p4-docs branch July 2, 2026 19:16
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