Syllabus Lesson 100 of 148 · Judge the output
Judge the output

Spec before you ask

Why it matters "Remove duplicate emails" sounds complete. It leaves five decisions open, and an assistant will make all five without telling you.

The assistant output in this lesson was written for the course in the exact shape real assistants produce. It is not a recording of any particular model.

A teammate asked an assistant, six times in six chats, to "write a function that removes duplicate emails from a list". The six answers all look reasonable, and each made a different silent choice: order, letter case, spaces, plus tags, empty entries, and whether the input list is changed.

The fix is to decide first and write the decisions as an acceptance test, then ask. The test is the spec: it goes into the prompt, and it checks whatever comes back.

The team's decisions

  • Two addresses are the same when they match after trimming spaces and ignoring letter case.
  • Keep the first one of each, trimmed but otherwise as written, in the original order.
  • Drop entries that are empty after trimming.
  • ana+news@shop.example and ana@shop.example are different: the shop sends to exactly what was typed.
  • Return a new list; never change the list passed in.
Your turn

Write acceptance(dedupe): a test that calls dedupe(emails) on inputs you choose and raises (for example with assert) when the function breaks any of the team's decisions. It runs against the six assistant answers and a correct version. Pass bar: pass the correct version and catch at least 5 of the 6 answers.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.