Due Fri 10/15 11:59pm
Run the file and observe that the test cases in the file (which are correct) all pass. Formulate a property that should hold for topological sort and then find an input that fails to satisfy that property. Use random testing. Once you have that input, turn it into a small test case. Fix the bug.
|;; taken from wikipedia: https://en.wikipedia.org/wiki/Topological_sorting|
|(define (kahns-algorithm original-graph)|
|(define ig (invert original-graph))|
|(define g (copy-graph original-graph))|
|(define L '())|
|(define S (no-incoming-edges g))|
|(let loop ()|
|(unless (empty? S)|
|(define n (first S))|
|(set! L (cons n L))|
|(set! S (rest S))|
|(for ([m (in-list (neighbors g n))])|
|(remove-edge! g n m)|
|(remove-edge! ig m n)|
|(when (empty? (neighbors ig n))|
|(set! S (cons m S))))|
|[(has-edges? g) #f]|
|[else (reverse L)]))|
|;; test cases go into the submodule `test`|
|;; by convention. DrRacket will run these|
|;; for your automatically; at the command-line,|
|;; use `raco test file.rkt` to run them|
|(new-graph '(("a" "a"))))|
|(new-graph '(("a" "b")|
|(list "a" "b" "c")))|
Implement the other topological sorting algorithm from the wikipedia page and use random testing to try to find bugs in your implementation, using the property that you developed for the previous version. The graph library comes with a function to make up a graph. Strive to make a correct implementation, using the random testing as well as unit testing of your own to help you.
Note: to implement the marking, have two local variables that hold hash tables mapping strings to booleans. Do not need to change the graph library.
Submit a single racket file with your solution via Canvas.