= Exercise 5.11
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 5.11
:action: actions/workflows/ch5ex11.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]
{badge-exercise}
The instructor of the _linear algebra_ course decides that
_calculus_ is now a prerequisite.
Extend the `topoSort` function to report cycles.
== Test
In validating the list produced by `topoSort`
in _Exercise 5.10_, we accidentally figured out
how to detect a cycle in a graph.
We add a new test `TestTopoSortCyclicGraph`
which errors if `topoSort` fails to detect a cyclic graph,
on top of all the checks we already performed
in _Exercise 5.10_.
The new `topoSort` implements
uses an additional map `dependents`
to detect cyclic dependencies and
returns an error if the graph has a cycle.