scientific-tdd

Implement test-driven development for scientific code using pytest-based tests.

3|1|Updated Jun 7, 2023
One-click install
npx skills add https://github.com/LorenFrankLab/non_local_detector --skill scientific-tdd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: scientific-tdd
Source: https://github.com/LorenFrankLab/non_local_detector/tree/main/.claude/skills/scientific-tdd
Command: npx skills add https://github.com/LorenFrankLab/non_local_detector --skill scientific-tdd

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, numpy.

What problem does it solve?

Scientific code often harbors subtle bugs due to a lack of rigorous testing, leading to reproducibility issues, unreliable results, and time-consuming debugging. This Skill provides a structured, pragmatic Test-Driven Development (TDD) approach tailored for scientific projects, ensuring your code is correct and robust from the start.

Core Features & Use Cases

  • Test-First Development: Write tests before implementation for new features and complex algorithms, guaranteeing desired behavior.
  • Bug Fix Verification: Quickly write tests to confirm simple bug fixes, preventing regressions.
  • Numerical Validation Integration: Seamlessly integrate with numerical validation processes to ensure mathematical correctness.
  • Use Case: When implementing a new Bayesian inference model for neural data, use this Skill to define expected outputs and edge cases with tests before writing the model, ensuring its mathematical integrity and preventing costly errors.

Quick Start

Follow the TDD checklist for your next feature:

1. Understand existing behavior

2. Write a failing test (RED)

3. Run test to confirm RED

4. Implement minimal code to pass test

5. Run test to confirm GREEN

6. Run full test suite

7. Run numerical validation (if applicable)

8. Refactor if needed

9. Commit with descriptive message

Frequently Asked Questions about scientific-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement test-driven development for scientific code?

Test-driven development for scientific code follows a red-green-refactor workflow: write a failing test first, run it to confirm failure, implement minimal code to pass, run the test to confirm success, then refactor. Use pytest to structure tests, include numerical validation checks for mathematical correctness, and commit with descriptive messages documenting each step.

Why is testing important for scientific computing and numerical methods?

Scientific code often contains subtle bugs that compromise reproducibility and result reliability. Testing numerical methods and algorithms before deployment catches correctness issues early, validates mathematical assumptions, ensures stability of calculations, and prevents costly errors in research outcomes and publications.

Can I use pytest with numpy for numerical testing?

Yes. Pytest integrates seamlessly with numpy for scientific testing. Write tests that validate numerical outputs against expected ranges, check edge cases, and verify stability of mathematical operations. Pytest fixtures can initialize numpy arrays and pytest parametrize can test multiple numerical scenarios efficiently.

What should I test when writing scientific code with complex algorithms?

Test edge cases, boundary conditions, and mathematical invariants. For algorithms and numerical models, verify outputs match expected behavior, validate numerical stability, check that mathematical properties hold, and confirm results are reproducible. Write tests before implementation to define expected behavior upfront.

How do I catch bugs in existing scientific code quickly?

Write a failing test that reproduces the bug, then fix the code to make the test pass. This approach confirms the fix works and prevents regression. For numerical bugs, include validation checks that verify the corrected mathematical behavior against known correct outputs or theoretical expectations.

What's the best way to ensure code quality in scientific Python projects?

Combine test-driven development with pytest-based testing and numerical validation. Write tests before implementing features, run your full test suite regularly, validate numerical results for mathematical correctness, and document test creation and execution in commit messages to maintain code quality throughout development.