Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SamXop123 wants to merge 2 commits into TheAlgorithms:master
base: master
Choose a base branch
Loading
from SamXop123:test/graphs-add-core-tests

Conversation

@SamXop123
Copy link

@SamXop123 SamXop123 commented Oct 15, 2025
edited
Loading

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.

Copy link

codecov-commenter commented Oct 15, 2025
edited
Loading

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

Reviewers

@raklaptudirm raklaptudirm Awaiting requested review from raklaptudirm raklaptudirm is a code owner

@appgurueu appgurueu Awaiting requested review from appgurueu appgurueu is a code owner

At least 2 approving reviews are required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /