Catch the bug that looks right

मॉड्यूल 1: Code with AI, and check every line

कोर्स की रूपरेखा

यह पाठ अभी आपकी भाषा में नहीं है, इसलिए यहाँ अंग्रेज़ी में है।

गलतियाँ पकड़ें

Guess first, no penalty. An AI wrote average_order_value(). Customer A has orders of 10 and 20, customer B one order of 100. A's result comes out as 65.0, not 15.0. Tap the line that causes it.

The function, line by line

1 में से 0 मिलीं

The worst AI bugs don't crash. The code runs and returns tidy numbers, and they're wrong. A quick read misses them because each line looks fine on its own.

Two habits catch them:

  • Trace one small example by hand. Pick inputs you can work out in your head and compare with what the code returns.
  • Write a test with mixed input. One customer hides this bug, because the shared total is that customer's total. Two customers expose it.

The expected value in a test comes from your hand trace or the requirement. Never paste in what the code returned, or the test locks the bug in.

A worked example

Hand trace:  A = (10 + 20) / 2 = 15.0    B = 100 / 1 = 100.0
Code says:   A = 65.0                    B = 130.0      -> bug

Fix: keep one total per customer:
    totals[c] = totals.get(c, 0) + order["amount"]

Test I keep:
    orders = [{"customer": "A", "amount": 10.0},
              {"customer": "A", "amount": 20.0},
              {"customer": "B", "amount": 100.0}]
    assert average_order_value(orders) == {"A": 15.0, "B": 100.0}

खाली जगह भरें

Fill the gaps.

Test plan

I use so a shared total shows. The expected value comes from , and the assert checks .

Try it

आपके स्टेप, लगभग 2 मिनट

1 में से 0
  1. 1.Trace a small, mixed example by hand for one function an AI wrote for you, and turn it into a test. Add "trace one mixed example" to your kit.2 मिनट

प्रैक्टिस

2 में से सवाल 1

You're writing a test for an AI-written function. Where should the expected value come from?

AI ट्यूटर

इस पाठ के बारे में सवाल पूछें और “करके देखें” वाले काम में मदद पाएँ। ट्यूटर Learn Pro का हिस्सा है।

Learn Pro देखें