How Hello-Algo Validates Algorithm Code Examples Across Programming Languages

The Hello-Algo repository uses per-language test harnesses combined with GitHub Actions workflows to automatically execute every algorithm implementation on Ubuntu, macOS, and Windows, ensuring cross-platform correctness.

The open-source educational project Hello-Algo (krahets/hello-algo) maintains parallel implementations of fundamental algorithms across more than a dozen programming languages. To guarantee that every code example remains functional and consistent, the project employs a robust validation pipeline that automatically tests each language-specific implementation on every commit.

Per-Language Test Harnesses

The validation strategy centers on language-specific test harnesses located in the codes/ directory. Each harness discovers and executes algorithm files following the chapter_*/* pattern, failing immediately upon encountering any non-zero exit status. This design ensures that syntax errors, runtime exceptions, or API mismatches are caught before they reach readers.

JavaScript and Node.js/Deno Validation

For JavaScript, the harness file codes/javascript/test_all.js uses Deno to spawn Node.js processes for every chapter_*.js file discovered in the repository. The script executes each algorithm with deno run -A and monitors the exit code, failing the validation if any process returns an error.

deno run -A codes/javascript/test_all.js

This approach validates both the Deno and Node.js compatibility of the JavaScript examples.

Python Validation

The Python harness in codes/python/test_all.py utilizes glob.glob to discover all chapter_*.py files, then executes each via subprocess.Popen. The script raises an exception and aborts the validation run if any script exits with a non-zero code.

python codes/python/test_all.py

Ruby Validation

Ruby validation is handled by codes/ruby/test_all.rb, which employs Open3.capture3 to execute each chapter_*.rb file. This method captures stdout, stderr, and the exit status simultaneously, allowing the harness to detect failures immediately and halt execution.

ruby codes/ruby/test_all.rb

C# (.NET) Validation

Unlike the interpreted languages, the C# validation leverages the NUnit testing framework. Each algorithm file, such as codes/csharp/chapter_tree/binary_tree.cs, contains [Test] methods that verify functionality. The harness invokes dotnet test on the project file to build and execute all tests.

dotnet test codes/csharp/hello-algo.csproj

A failing NUnit test causes the job to fail, ensuring that both compilation errors and logic bugs are detected.

Other Supported Languages

Go, Rust, Swift, Kotlin, TypeScript, Dart, and additional languages follow the same architectural pattern: each maintains a dedicated test-all script or utilizes native test frameworks (such as go test or cargo test), invoked by corresponding GitHub Actions workflows.

Cross-Platform CI Integration

The validation pipeline integrates with GitHub Actions to enforce quality gates on every push and pull request. Each language has a dedicated workflow file in .github/workflows/:

These workflows execute the language-specific harnesses across three operating systems—Ubuntu, macOS, and Windows—guaranteeing that code examples work correctly on all major development environments. The fail-fast behavior ensures that as soon as any script returns a non-zero status, the CI job records the error and terminates, making integration failures immediately visible to contributors.

Running Validation Locally

Contributors can execute the same validation checks locally before submitting changes. Below are the commands for running the test harnesses on your machine:


# Validate all JavaScript examples

deno run -A codes/javascript/test_all.js

# Validate all Python examples

python codes/python/test_all.py

# Validate all Ruby examples

ruby codes/ruby/test_all.rb

# Validate all C# examples

dotnet test codes/csharp/hello-algo.csproj

Summary

  • Self-contained examples: Each algorithm file includes a main-like driver that executes without external input, enabling automated testing.
  • Uniform discovery: Harnesses use glob patterns (chapter_*/*.ext) to automatically include new algorithms without manual registration.
  • Cross-platform coverage: GitHub Actions runs every validation suite on Linux, macOS, and Windows.
  • Fail-fast validation: Non-zero exit codes trigger immediate failures, preventing broken code from merging.
  • Framework integration: C# uses NUnit [Test] attributes, while interpreted languages use custom harnesses with subprocess or Open3.

Frequently Asked Questions

How does Hello-Algo ensure that new algorithm files are automatically tested?

The test harnesses use glob patterns like chapter_*/*.py or chapter_*.js to discover files dynamically. When contributors add a new algorithm file following the chapter_* naming convention, the harness automatically includes it in the next validation run without requiring manual updates to the test configuration.

Why does the JavaScript validation use Deno to run Node.js processes?

The codes/javascript/test_all.js harness uses deno run -A to execute Node.js processes because it provides a secure, modern runtime environment for orchestrating the tests while validating that the actual algorithm code remains compatible with standard Node.js execution. This dual-runtime approach ensures broad compatibility across JavaScript ecosystems.

What happens when a code example fails validation?

When any script exits with a non-zero status, the language-specific harness immediately records the error and aborts the validation run. In the CI pipeline, this triggers a workflow failure, preventing the pull request from merging until the issue is resolved. This fail-fast approach ensures that only working code reaches the main branch.

Does the C# validation differ significantly from other languages?

Yes, while Python, Ruby, and JavaScript use custom scripts that execute files directly via subprocess, the C# validation leverages the .NET ecosystem's native NUnit testing framework. Algorithm files contain [Test] methods that dotnet test discovers and executes, providing more granular test reporting while maintaining the same cross-platform CI integration via .github/workflows/dotnet.yml.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →