Panshi
← 服务

🧪 单元测试生成

粘贴一个函数或模块,生成可运行的单测套件——覆盖正常路径、边界、非法输入和异常路径。

先看产出质量 —— 真实示例

示例 · 不消耗点数

输入 — 被测函数

框架:pytest

def apply_discount(price, percent):
    """按百分比打折后返回价格,保留 2 位小数。"""
    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)

输出 — 生成的测试套件

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)

覆盖的用例

  • test_basic_discount — 正常路径,100 打 8 折
  • test_rounds_to_two_dp — 四舍五入到 2 位小数
  • test_zero/full_discount — 0% 与 100% 边界
  • test_negative_price_raises — 非法输入异常路径
  • test_percent_out_of_range_raises — 参数化 −5 和 101

说明: 假设 import 路径为 pricing,请改成你的模块名。遇到不确定我们会标注假设,绝不默默瞎猜。

相关工具

文本转 SQL

用大白话生成 PostgreSQL / MySQL / SQLite / BigQuery / Snowflake 的正确 SQL —— 理解表结构。

代码审查

贴一段 diff 或代码,得到分级审查 —— bug / 逻辑 / 安全 / 性能 —— 附修复建议。

Excel 公式

用大白话描述需求,得到精确的 Excel / Google Sheets 公式 —— 附通俗解释。

遗留代码解读

粘贴看不懂的代码,得到逐段讲解、数据流和风险点。

FAQ

单元测试生成多少钱?

每次运行约 9 点(1 点 = $0.01)。注册即送 30 点,可先免费试。不订阅 —— 用多少付多少,点数永不过期。

我的数据安全吗?

你的输入只用于生成这一次结果;结果保存在你自己的账户历史里,不对外分享,也不用于训练模型。

结果不满意怎么办?

14 天内若工具未能给出可用结果,我们退款或补发点数 —— 邮件 hi@panshi.io 即可。

需要订阅吗?

不需要。一次性购买点数即可贯通全部工具,无月费,永不过期。