From 19bb120207bfdccb968795a236f19e7b97f0b267 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Thu, 14 May 2009 15:33:25 +0000 Subject: [PATCH] added tests for topological-sort svn: r14814 original commit: 40467a005ecfbbdab5f6265ed8723cb51dc78ba5 --- collects/tests/profile/topsort.ss | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 collects/tests/profile/topsort.ss diff --git a/collects/tests/profile/topsort.ss b/collects/tests/profile/topsort.ss new file mode 100644 index 0000000..4af71e2 --- /dev/null +++ b/collects/tests/profile/topsort.ss @@ -0,0 +1,52 @@ +#lang scheme/base + +(require tests/eli-tester profile/structs profile/utils) + +(define (connect! from to) + (define e (make-edge 0 from 0 to 0)) + (set-node-callers! to (cons e (node-callers to ))) + (set-node-callees! from (cons e (node-callees from)))) + +(define-syntax with-graph + (syntax-rules (->) + [(_ [] -> -> more ...) + (begin (connect! ) (with-graph [] -> more ...))] + [(_ [] -> more ...) + (begin (connect! ) (with-graph [] more ...))] + [(_ [] more ...) (begin more ...)] + [(_ [ ...] more ...) + (let ([ (make-node ' #f '() 0 0 '() '())] ...) + (with-graph [] more ...))])) + +(provide topological-sort-tests) +(define (topological-sort-tests) + (test + + do (with-graph [A B C] + A -> B -> C + (test (topological-sort A values) => (list A B C))) + + do (with-graph [A B C] + ;; check that a cycle doesn't lead to dropping nodes + A -> B -> C -> A + A -> C -> B -> A + (null? (remq* (topological-sort A values) (list A B C)))) + + do (with-graph [A B C D] + A -> B -> C -> D + A -> D + (test (topological-sort A values) => (list A B C D))) + + do (with-graph [A B C] + A -> B + A -> C + C -> C + (test (memq C (topological-sort A)))) + + do (with-graph [A B C D] + A -> B + A -> C -> D + A -> D -> C + (test (memq C (topological-sort A)))) + + ))