Calculate · Assess & Decide · Engineering
Cyclomatic complexity with refactor flags
McCabe cyclomatic complexity per function from its control-flow graph, with a refactor flag for any that exceed your threshold.
You receive: A reviewed complexity calculator + the passing test report, run on your control-flow graphs.
Part of Ship MVP
Opens soon
Cost15 credits
AcceptanceAutomated check against your inputs
ProtectionHeld until verified delivery
This objective is verified and ready. It opens soon, once sign-in and payments are live.
Deliverable interface
The exact vocabulary the automated check enforces: keys, tokens, entry points, and worked examples. Generated from the verification source.
{
"constants": {},
"entryName": "compute_cyclomatic_complexity",
"expectNote": "expect is the comparison-space value (your return value goes through normalize first when one is published)",
"hiddenCaseCount": 6,
"hiddenCaseNames": [
"under_threshold",
"two_components_2p",
"two_components_1p",
"at_threshold_not_exceeds",
"multi_graph_order_preserved",
"invalid_missing_node_count"
],
"inputKeys": [
"component_mode",
"components",
"edges",
"graphs",
"name",
"nodes",
"refactor_threshold"
],
"normalizeSource": "def _cyclomatic_normalize(r):\n if isinstance(r, str):\n return r # sentinel (e.g. invalid_graph) passes through\n try:\n return {\"rows\": [{\"name\": str(x[\"name\"]), \"complexity\": int(x[\"complexity\"]),\n \"exceeds_threshold\": bool(x[\"exceeds_threshold\"])} for x in r[\"rows\"]]}\n except Exception:\n return repr(r)\n",
"returnShapes": [
[
"rows"
],
"invalid_graph"
],
"signature": "def compute_cyclomatic_complexity(inp):",
"submission": "python exposing the entry function; inp is one input object; graded on held-out cases",
"tier": "calculator",
"visibleCases": [
{
"expect": {
"rows": [
{
"complexity": 1,
"exceeds_threshold": false,
"name": "f"
}
]
},
"input": {
"component_mode": "1p",
"graphs": [
{
"components": 1,
"edges": 4,
"name": "f",
"nodes": 4
}
],
"refactor_threshold": 10
},
"name": "single_if_else"
},
{
"expect": {
"rows": [
{
"complexity": 2,
"exceeds_threshold": false,
"name": "g"
}
]
},
"input": {
"component_mode": "1p",
"graphs": [
{
"components": 1,
"edges": 9,
"name": "g",
"nodes": 8
}
],
"refactor_threshold": 10
},
"name": "worked_a"
}
],
"vocabulary": [
"1p",
"2p",
"complexity",
"component_mode",
"components",
"edges",
"exceeds_threshold",
"graphs",
"invalid_graph",
"name",
"nodes",
"refactor_threshold",
"rows"
]
}Get early access to STUD the day it goes live.