跳到正文
cccskills

test-driven-development 的测试记录

按任务列出请求、评分项及每项得分、每次运行的时间和 token、Claude Code 的完整日志以及生成的文件。另附原始数据,便于在调整配分后重新计算。

2026年11月24日 运行(运行:claude-sonnet-5-5/评分:claude-opus-5-5)。数值为中位数。任务由 AI 根据 SKILL.md 编写,可能偏向对该技能有利的场景。

原始数据(JSON)按原样提供任务、每次运行的测量值、评分和汇总。

每次运行的测量值

运行结果时间Token费用轮次使用技能日志
任务 1 第 1 次 不使用技能完成12 秒68,086$0.0497-完整日志
任务 1 第 1 次 使用技能完成18 秒136,394$0.08110使用完整日志
任务 1 第 1 次 使用技能(未点名)完成18 秒112,625$0.07910使用完整日志
任务 1 第 2 次 使用技能完成19 秒112,290$0.06310使用完整日志
任务 1 第 2 次 不使用技能完成13 秒67,745$0.0274-完整日志
任务 1 第 2 次 使用技能(未点名)完成15 秒111,054$0.0577使用完整日志
任务 2 第 1 次 不使用技能完成15 秒51,080$0.0424-完整日志
任务 2 第 1 次 使用技能完成27 秒139,131$0.0919使用完整日志
任务 2 第 1 次 使用技能(未点名)完成19 秒107,487$0.0588未使用完整日志
任务 2 第 2 次 使用技能完成21 秒139,662$0.0769使用完整日志
任务 2 第 2 次 不使用技能完成14 秒69,091$0.0315-完整日志
任务 2 第 2 次 使用技能(未点名)完成22 秒107,573$0.0458未使用完整日志

“使用技能(未点名)”的运行只用于测量调用率,不参与评分。

任务 1: 修复 Python 定价模块中批量折扣的边界错误

请求

We got a bug report from support: "A customer ordered exactly 10 units of SKU A-100 at $4.99 each and was charged the full $49.90 — they should have gotten the bulk discount." Can you fix this in pricing.py? Please make sure it doesn't happen again.

评分标准

  1. pricing.py is fixed so that exactly 10 units gets 10% off (line_total(499, 10) == 4491) and exactly 50 units gets 20% off; quantities of 9 and 49 still get the lower tier
  2. Test(s) were added under tests/ that cover the reported case (exactly 10 units) and the boundary values around both tiers (e.g. 9/10 and 49/50)
  3. All pre-existing tests still pass unchanged, and the full suite passes with `python3 -m unittest discover -s tests`
  4. The final message explains the root cause (strict > comparisons instead of >=), notes the 50-unit boundary had the same bug, and reports the actual test run result

每个评分项的得分(1 = 满足・0.5 = 部分・0 = 未满足)

#第 1 次
不使用技能 / 使用技能
第 2 次
不使用技能 / 使用技能
11 / 11 / 1
21 / 11 / 1
31 / 11 / 1
41 / 11 / 1
初始文件(3)

README.md

# pricing

Small pricing helpers used by the checkout service.

## Bulk discount policy

- 10 or more units of a line item: 10% off that line
- 50 or more units of a line item: 20% off that line
- Discounted line totals are rounded to the nearest cent (half up).

## Running tests

```
python3 -m unittest discover -s tests -v
```

pricing.py

"""Pricing helpers. All money values are integer cents."""


def bulk_discount_rate(qty):
    """Return the discount rate for a line with `qty` units.

    Policy: 10 or more units -> 10%, 50 or more units -> 20%.
    """
    if qty < 0:
        raise ValueError("qty must be non-negative")
    if qty > 50:
        return 0.20
    if qty > 10:
        return 0.10
    return 0.0


def line_total(unit_price_cents, qty):
    """Total for a line in cents, after bulk discount, rounded half up."""
    if unit_price_cents < 0:
        raise ValueError("unit price must be non-negative")
    gross = unit_price_cents * qty
    rate = bulk_discount_rate(qty)
    # integer math to avoid float rounding surprises: percent as integer
    percent_off = int(round(rate * 100))
    discounted_times_100 = gross * (100 - percent_off)
    return (discounted_times_100 + 50) // 100


def order_total(lines):
    """lines: iterable of (unit_price_cents, qty)."""
    return sum(line_total(p, q) for p, q in lines)

tests/test_pricing.py

import os
import sys
import unittest

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

from pricing import bulk_discount_rate, line_total, order_total  # noqa: E402


class BulkDiscountRateTest(unittest.TestCase):
    def test_small_order_has_no_discount(self):
        self.assertEqual(bulk_discount_rate(3), 0.0)

    def test_mid_size_order_gets_ten_percent(self):
        self.assertEqual(bulk_discount_rate(25), 0.10)

    def test_large_order_gets_twenty_percent(self):
        self.assertEqual(bulk_discount_rate(100), 0.20)

    def test_negative_qty_rejected(self):
        with self.assertRaises(ValueError):
            bulk_discount_rate(-1)


class LineTotalTest(unittest.TestCase):
    def test_no_discount_line(self):
        self.assertEqual(line_total(499, 2), 998)

    def test_discounted_line_rounds_half_up(self):
        # 15 * 333 = 4995; 10% off = 4495.5 -> 4496
        self.assertEqual(line_total(333, 15), 4496)


class OrderTotalTest(unittest.TestCase):
    def test_sums_lines(self):
        self.assertEqual(order_total([(499, 2), (100, 1)]), 1098)


if __name__ == "__main__":
    unittest.main()

第 1 次: 平局 (达成率 100% / 100%)

两者均同样改为>=,添加边界测试,说明原因及50件同类缺陷并报告测试结果,无实质差异

不使用技能100%

最终回复

I fixed the bug in pricing.py. All 10 tests pass, including the new ones.

Cause: bulk_discount_rate used qty > 10 and qty > 50. The documented policy, in the docstring and the README, says "10 or more" and "50 or more". An order of exactly 10 got no discount, and so did an order of exactly 50, which also missed the 20% tier. I changed both comparisons to >=.

Result: 10 units at $4.99 now come to $44.91 (10% off) instead of $49.90. 50 units now get 20% off.

Regression tests in tests/test_pricing.py:

  • Rate boundaries at 9, 10, 49 and 50.
  • line_total(499, 10) == 4491, which is the exact case from the support report.
  • line_total(499, 50) == 19960.

The existing tests used quantities of 3, 25 and 100, which never touched a boundary. That's why the bug wasn't caught.

I haven't looked for customers who were already overcharged on orders of exactly 10 or 50 units. Support may want to check for refunds.

新建或修改的文件

使用技能100%

最终回复

Fixed. An order of exactly 10 units now gets the bulk discount, and all 13 tests pass.

Cause: bulk_discount_rate in pricing.py used qty > 10 and qty > 50. The documented policy is "10 or more" and "50 or more", so both thresholds were off by one. Orders of exactly 50 units were also getting 10% instead of 20%. That second bug wasn't in the report.

Fix: I changed both comparisons to >=.

Tests: I added tests before the fix and confirmed 4 of them failed against the old code.

  • Boundaries: the rate at 9, 10, 49 and 50 units.
  • Reported case: 10 × $4.99 now totals $44.91 (4491¢) instead of $49.90.
  • 50-unit case: 50 × $4.99 now totals $199.60 (19960¢).

These pin the boundaries, so a future change to the comparisons will fail the suite.

The customer in the report was overcharged $4.99. Any other orders of exactly 10 or 50 units were overcharged too. You may want to look for those and refund them, but that's outside this code.

新建或修改的文件

第 2 次: 平局 (达成率 100% / 100%)

双方均做了相同的>=修复,添加9/10/49/50边界测试,说明根因及50件问题并报告测试结果,无实质差异。

不使用技能100%

最终回复

Fixed. The tier checks in bulk_discount_rate used > instead of >=, so the discount only started at 11 units and 51 units. That didn't match the policy in the README and docstring ("10 or more", "50 or more"). I changed both checks to >= in pricing.py.

An order of 10 units at $4.99 now comes to $44.91 (10% off) instead of $49.90. The same bug hit exactly 50 units, which now get 20% off.

To keep it from coming back, I added three tests to tests/test_pricing.py:

  • Tier boundaries: checks 9, 10, 49 and 50 units.
  • Reported case: 10 × 499¢ = 4491¢.
  • 50 units: 50 units at 100¢ = 4000¢.

All 10 tests pass.

Any customers who already bought exactly 10 or exactly 50 units were overcharged. Support may want to find those orders and refund the difference. The code can't tell me which orders those are.

新建或修改的文件

使用技能100%

最终回复

I fixed the bug in pricing.py. The customer's 10 units at $4.99 now come to $44.91 (10% off) instead of $49.90. All 12 tests pass.

Cause: bulk_discount_rate used qty > 10 and qty > 50. The policy in the docstring and README says "10 or more" and "50 or more". The same off-by-one meant orders of exactly 50 units got 10% off instead of 20%. I fixed both thresholds to >=.

Tests added to tests/test_pricing.py:

  • Customer's case: line_total(499, 10) should equal 4491. This test failed before the fix with 4990.
  • Boundary cases: the rate at 9, 10, 49 and 50 units. The tests at 10 and 50 failed before the fix.

The existing tests used 3, 25 and 100 units, so they never hit a threshold. That's why the bug got through.

Orders of exactly 10 or 50 units were undercharged for the discount before this fix. You may want to tell support so they can look at past orders for refunds.

新建或修改的文件

任务 2: 为 Node.js slugify 增加去重音和最大长度选项

请求

Our slugify in src/slugify.js produces ugly URLs for some blog titles. Please change it so that:
1. Accented letters are transliterated instead of dropped: "Café Déjà Vu" should become "cafe-deja-vu" (right now it's "caf-dj-vu").
2. Runs of dashes collapse to one and there are never leading/trailing dashes: "a -- b" -> "a-b", "-Hello-" -> "hello".
3. It accepts an optional second argument `{ maxLength }`. When the slug is longer, cut it at the last dash boundary that fits so words aren't split, with no trailing dash. If the first word alone is longer than maxLength, just hard-cut it to maxLength.
Existing behavior that callers rely on must keep working.

评分标准

  1. slugify('Café Déjà Vu') returns 'cafe-deja-vu'
  2. slugify('a -- b') returns 'a-b' and slugify('-Hello-') returns 'hello' (no repeated, leading, or trailing dashes)
  3. maxLength works as specified: e.g. slugify('The quick brown fox', { maxLength: 12 }) returns 'the-quick' (word boundary, no trailing dash), a single over-long word is hard-cut to exactly maxLength, and slugs already within the limit are unchanged
  4. All original tests in test/slugify.test.js still pass, and new tests were added covering each of the three requested behaviors
  5. The suite was run with the project's command (`npm test` / `node --test test/`) and the final message reports the actual result

每个评分项的得分(1 = 满足・0.5 = 部分・0 = 未满足)

#第 1 次
不使用技能 / 使用技能
第 2 次
不使用技能 / 使用技能
11 / 11 / 1
21 / 11 / 1
31 / 11 / 1
40 / 10.5 / 1
50 / 10.5 / 1
初始文件(3)

package.json

{
  "name": "blog-utils",
  "version": "1.0.0",
  "private": true,
  "type": "commonjs",
  "scripts": {
    "test": "node --test test/"
  }
}

src/slugify.js

'use strict';

/**
 * Turn a post title into a URL slug.
 * @param {string} input
 * @returns {string}
 */
function slugify(input) {
  return String(input)
    .toLowerCase()
    .trim()
    .replace(/[^a-z0-9\s-]/g, '')
    .replace(/\s+/g, '-');
}

module.exports = { slugify };

test/slugify.test.js

'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const { slugify } = require('../src/slugify');

test('lowercases and joins words with dashes', () => {
  assert.equal(slugify('Hello World'), 'hello-world');
});

test('drops punctuation', () => {
  assert.equal(slugify('Rock & Roll!'), 'rock-roll');
});

test('trims surrounding whitespace', () => {
  assert.equal(slugify('  Trim me  '), 'trim-me');
});

test('keeps existing dashes', () => {
  assert.equal(slugify('Already-slugged'), 'already-slugged');
});

test('keeps digits', () => {
  assert.equal(slugify('Top 10 Tips'), 'top-10-tips');
});

第 1 次: 使用技能 (达成率 60% / 100%)

两者实现均正确,但B未添加新测试且无可验证的测试运行结果。

不使用技能60%

最终回复

I updated slugify in src/slugify.js, and the 5 existing tests pass. I didn't add new test cases to the test file. I checked the new behavior by running a few examples by hand:

  • Accents: "Café Déjà Vu" now gives cafe-deja-vu. I also mapped ß, æ, œ, ø, đ, ð, þ and ł to ASCII equivalents, because accent-stripping alone doesn't handle them.
  • Dashes: "a -- b" gives a-b and "-Hello-" gives hello. Runs of spaces and dashes collapse to one dash, and leading and trailing dashes are removed.
  • { maxLength }:
    • slugify('hello world foo', { maxLength: 11 }) gives hello-world.
    • slugify('hello world foo', { maxLength: 12 }) also gives hello-world, since the full slug wouldn't fit.
    • slugify('abcdefghij kl', { maxLength: 5 }) gives abcde, because the first word alone is too long, so it's hard-cut.

The second argument is optional, so existing one-argument calls behave as before. For example, "Rock & Roll!" still gives rock-roll.

新建或修改的文件

使用技能100%

最终回复

slugify in src/slugify.js now handles all three changes. All 12 tests pass: the 5 existing ones plus 7 new ones in test/slugify.test.js.

  • Accents: "Café Déjà Vu" becomes cafe-deja-vu.
  • Dashes: runs collapse to one dash and there are no leading or trailing dashes, so "a -- b" becomes a-b and "-Hello-" becomes hello.
  • { maxLength }:
    • When the slug is longer, it cuts at the last dash that fits, with no trailing dash.
    • If the first word alone is longer than maxLength, it hard-cuts it.
    • Without the option, or with a non-numeric one, behavior is unchanged.

To confirm the new tests were real, I temporarily restored the old implementation. 6 of the 7 new tests failed, and the existing 5 still passed. The seventh, "leaves slug alone when within maxLength", passes on the old code too. The old code ignores the second argument, so it returns the short slug unchanged.

npm test is broken in this environment, and I didn't change it. Node 22 reads node --test test/ as a module path and fails with "Cannot find module '/work/test'". I ran node --test test/slugify.test.js instead. Changing the script to node --test would fix it if you want that.

新建或修改的文件

第 2 次: 使用技能 (达成率 80% / 100%)

两者实现均正确,但B为三项新功能都添加了测试,并写明了运行命令和结果

不使用技能80%

最终回复

I updated slugify in src/slugify.js, and all 5 existing tests in test/slugify.test.js pass. I didn't add tests for the new behavior. I checked it with a quick script instead.

  • Accents: accented letters are now transliterated, so "Café Déjà Vu" gives cafe-deja-vu. I also mapped ß, æ, œ, ø, đ, ð, þ and ł, which don't decompose into a base letter plus an accent.
  • Dashes: runs of dashes and spaces collapse to one dash, and leading and trailing dashes are stripped. "a -- b" gives a-b and "-Hello-" gives hello.
  • { maxLength }: a slug that is too long is cut at the last dash that fits, with no trailing dash. If the first word alone is too long, it's hard-cut to maxLength.
  • Invalid maxLength: a missing, zero, negative or non-numeric maxLength is ignored.

In my check, hello world foo with maxLength: 11 gave hello-world, and abcdefghij k with maxLength: 5 gave abcde.

新建或修改的文件

使用技能100%

最终回复

I changed slugify in src/slugify.js to do all three things, and the tests pass: 13 of 13 with node --test test/slugify.test.js.

  • Accents: letters are transliterated, so "Café Déjà Vu" gives cafe-deja-vu.
  • Dashes: runs collapse to one, and there are no leading or trailing dashes. "a -- b" gives a-b and "-Hello-" gives hello.
  • { maxLength }: an over-long slug is cut at the last dash that fits, with no trailing dash. If the first word alone is longer than maxLength, it's hard-cut to maxLength. A missing or non-positive maxLength is ignored.

I added 8 tests to test/slugify.test.js before changing the code. Run against the original implementation, 7 of the 13 tests failed. The 5 existing tests still pass, so the old behavior callers rely on is unchanged.

npm test is broken in this environment: node --test test/ passes the directory as a module path and fails with "Cannot find module '/work/test'". I didn't change the script. Passing the file directly works, or node --test with no argument should find the tests.

新建或修改的文件