Skip to content
Panshi
EN / /
← Services

🧪 Unit Test Generator

Paste a function or module and get a runnable unit-test suite covering the happy path, boundaries, invalid inputs and error paths.

See the quality — a real example

Sample only · no credits used

Input — function under test

Framework: pytest

def apply_discount(price, percent):
    """Return price after a percent discount, rounded to 2dp."""
    if price < 0:
        raise ValueError("price must be non-negative")
    if not 0 <= percent <= 100:
        raise ValueError("percent must be 0..100")
    return round(price * (1 - percent / 100), 2)

Output — generated test suite

import pytest
from pricing import apply_discount

def test_basic_discount():
    assert apply_discount(100.0, 20) == 80.0

def test_rounds_to_two_dp():
    assert apply_discount(9.99, 15) == 8.49

def test_zero_percent_is_unchanged():
    assert apply_discount(50.0, 0) == 50.0

def test_full_discount_is_zero():
    assert apply_discount(50.0, 100) == 0.0

def test_negative_price_raises():
    with pytest.raises(ValueError):
        apply_discount(-1.0, 10)

@pytest.mark.parametrize("p", [-5, 101])
def test_percent_out_of_range_raises(p):
    with pytest.raises(ValueError):
        apply_discount(100.0, p)

Cases covered

  • test_basic_discount — happy path, 20% off 100
  • test_rounds_to_two_dp — rounding to 2 decimal places
  • test_zero/full_discount — boundaries at 0% and 100%
  • test_negative_price_raises — invalid input error path
  • test_percent_out_of_range_raises — parametrized −5 and 101

Note: import path assumed to be pricing — adjust to your module. We flag assumptions instead of guessing silently.

Related tools

Token Calculator

Count tokens (o200k / GPT-4o) and compare input/output cost across GPT, Claude, Gemini, DeepSeek & Qwen — runs in your browser.

API Key Leak Scanner

Paste code or config and instantly find hardcoded secrets — OpenAI/AWS/GitHub/Stripe/Google keys, private keys, JWTs. 100% in-browser.

Text to SQL

Turn plain English into correct SQL for Postgres, MySQL, SQLite, BigQuery or Snowflake — schema-aware.

Code Review

Paste a diff or file and get a ranked review — bugs, logic, security, performance — with fixes.