Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
A validation suite declares rules and a test suite claims to exercise them. The interesting output is not what is covered — it is which critical rule nobody wrote a case for, and which case is testing a rule id that does not exist.
Write rule_coverage(rules, cases). Report the counts and, more importantly, every gap.
Function to write
rule_coverage(rules: list[dict], cases: list[dict]) -> dictA report of per-rule coverage plus the untested rules, unknown ids and empty cases.
How to approach it
Ask which rule the starter can never mention, however many cases you add.
Sample cases
+ 2 held back until you submit
an untested critical rule and a typo
Everything the report exists for: an uncovered critical rule, a case testing nothing, and a rule id that does not exist.
Input
Argument 1
| id | severity |
|---|---|
| amount-positive | critical |
| buyer-present | warning |
| region-known | critical |
Argument 2
[
{
'name': 'happy path',
'covers': [
'amount-positive',
'buyer-present'
]
},
{
'name': 'smoke',
'covers': []
},
{
'name': 'typo',
'covers': [
'amount-postive'
]
}
]Returns
{
'coverage': [
{
'rule': 'amount-positive',
'cases': 1,
'severity': 'critical'
},
{
'rule': 'buyer-present',
'cases': 1,
'severity': 'warning'
},
{
'rule': 'region-known',
'cases': 0,
'severity': 'critical'
}
],
'untested': [
'region-known'
],
'untested_critical': [
'region-known'
],
'unknown_rules': [
{
'rule': 'amount-postive',
'cases': [
2
]
}
],
'cases_testing_nothing': [
{
'case': 1,
'name': 'smoke'
}
]
}no cases at all
Every rule is untested, which is the report's most important output and not an empty one.
Input
Argument 1
| id | severity |
|---|---|
| amount-positive | critical |
| buyer-present | warning |
| region-known | critical |
Argument 2
[] (empty list)
Returns
{
'coverage': [
{
'rule': 'amount-positive',
'cases': 0,
'severity': 'critical'
},
{
'rule': 'buyer-present',
'cases': 0,
'severity': 'warning'
},
{
'rule': 'region-known',
'cases': 0,
'severity': 'critical'
}
],
'untested': [
'amount-positive',
'buyer-present',
'region-known'
],
'untested_critical': [
'amount-positive',
'region-known'
],
'unknown_rules': [],
'cases_testing_nothing': []
}no rules and no cases
Nothing declared and nothing tested is a valid, empty report rather than an error.
Input
Argument 1
[] (empty list)
Argument 2
[] (empty list)
Returns
{
'coverage': [],
'untested': [],
'untested_critical': [],
'unknown_rules': [],
'cases_testing_nothing': []
}Constraints
coverage, untested, untested_critical, unknown_rules and cases_testing_nothing.coverage has one entry per declared rule, sorted by id, with its case count and severity. A rule nobody tested appears with a count of zero.untested lists the rule ids with no cases; untested_critical is the subset whose severity is critical.unknown_rules with the case indexes.cases_testing_nothing with its index and name.warning when a rule does not say.Worked example
Three rules are declared and two cases run. The case typo claims to cover amount-postive — one letter short of amount-positive.
A report built only from what the cases mention shows that as coverage and shows nothing about region-known, which is critical and has no case at all. Seeding the counts from the declared rules is what makes both visible: the typo becomes an unknown rule and the untested critical rule becomes the headline.
What this tests
That a coverage report is about absence, and absence cannot be discovered by iterating what is present. Seeding from the declaration rather than from the observations is the whole technique, and it applies well beyond tests.
rule_coverage(rules: list[dict], cases: list[dict]) -> dictSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.