Workspace/Coding labs
Loading progress

Check claims against fresh evidence

Intermediate65 min

Implement check_claim(evidence, claim, now, max_age). A claim names evidence_id, field, unit, and finite numeric minimum. Evidence records have time, unit, and a fields dictionary. Return unsupported for a missing record or field; stale when age is negative or greater than max_age; unit_mismatch for different units; otherwise supported or contradicted by value >= minimum. Apply checks in that stated order. Invalid nonnegative integer time controls or nonnumeric included values raise ValueError. Booleans are not numbers.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputcheck_claim({"o1":{"time":10,"unit":"items","fields":{"stock":2}}}, {"evidence_id":"o1","field":"stock","unit":"items","minimum":3}, 12, 5)

Output"contradicted"

Fresh evidence directly conflicts with the claim.
EXAMPLE 2

InputThe same claim at now=20, max_age=5

Output"stale"

Evidence outside the allowed age cannot support a current claim.
solution.pyPython 3.12