Skip to content

Conversation

SamXop123
Copy link

@SamXop123 SamXop123 commented Oct 15, 2025

Title

test(graphs): add tests for Dijkstra, DijkstraSmallestPath, FloydWarshall, KruskalMST, and DFS

Description

  • What’s added

    • Graphs/test/Dijkstra.test.js: Tests createGraph() and djikstra() from Graphs/Dijkstra.js with a weighted undirected graph; verifies shortest distances and parent initialization.
    • Graphs/test/DijkstraSmallestPath.test.js: Tests solve() from Graphs/DijkstraSmallestPath.js; asserts distances via dist property and validates path sequences via spread.
    • Graphs/test/FloydWarshall.test.js: Tests FloydWarshall() from Graphs/FloydWarshall.js; validates all-pairs shortest paths (including Infinity handling).
    • Graphs/test/KruskalMST.test.js: Tests GraphWeightedUndirectedAdjacencyList from Graphs/KruskalMST.js; verifies MST node set, edge count (nodes-1), total weight, and exclusion of heavy edge.
    • Graphs/test/DepthFirstSearchIterative.test.js: Tests GraphUnweightedUndirected.DFSIterative() from Graphs/DepthFirstSearchIterative.js; reachability positive/negative cases.
    • Graphs/test/DepthFirstSearchRecursive.test.js: Tests GraphUnweightedUndirected.DFSRecursive() from Graphs/DepthFirstSearchRecursive.js; reachability positive/negative cases.
  • Why

    • Improves coverage and guards against regressions for core graph algorithms.
    • Aligns with CONTRIBUTING.md guidance to “write proper tests.”
  • How to run

npm ci
npm test -- Graphs

Changes

  • Added test files only:
    • Graphs/test/Dijkstra.test.js
    • Graphs/test/DijkstraSmallestPath.test.js
    • Graphs/test/FloydWarshall.test.js
    • Graphs/test/KruskalMST.test.js
    • Graphs/test/DepthFirstSearchIterative.test.js
    • Graphs/test/DepthFirstSearchRecursive.test.js

No algorithm implementations or configs were modified.

Notes

  • DijkstraSmallestPath constructs path arrays that also carry a dist property (e.g., ['B', dist: 1]). Tests assert dist separately (e.g., res.B.dist) and compare the path sequence using spread (e.g., expect([...res.B])).
  • Tests use ES Modules and Vitest per repo standards.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work — I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames use the UpperCamelCase (PascalCase) style. There are no spaces in filenames.
  • No already existing files modified.

Summary

  • Added comprehensive tests for graph algorithms in Graphs/.
  • No changes to algorithm code; tests pass locally.
  • Ready for review and CI.

@codecov-commenter
Copy link

codecov-commenter commented Oct 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.90%. Comparing base (08d8c6b) to head (db2f3ff).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1843      +/-   ##
==========================================
+ Coverage   85.91%   87.90%   +1.98%     
==========================================
  Files         379      379              
  Lines       19778    19778              
  Branches     3015     3079      +64     
==========================================
+ Hits        16993    17386     +393     
+ Misses       2785     2392     -393     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants