1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# -*- tcl -*-
#Adjacency List - Tests
# Sort input into canonical form.
proc adjsort {dict} {
set res {}
foreach {k v} [dictsort $dict] {
lappend res $k [lsort -dict $v]
}
return $res
}
#Test 1.0 - undirected but weighted graph containing some special cases
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.0 { AdjacencyList, undirected, unweighted, graph simulation } {
SETUP_ADJACENCYLIST_K4
set result [struct::graph::op::toAdjacencyList mygraph]
mygraph destroy
set result
} "node1 {node2 node3 node4} node2 {node1 node3} node3 {node1 node2 node4} node4 {node1 node3}"
#Test 1.1 - undirected but weighted graph containing some special cases
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.1 { AdjacencyList, undirected, weighted, graph simulation } {
SETUP_ADJACENCYLIST_K4_WEIGHTED
set result [struct::graph::op::toAdjacencyList mygraph -weights]
mygraph destroy
set result
} "node1 {{node2 1} {node3 1} {node4 1}} node2 {{node1 1} {node3 1}} node3 {{node1 1} {node2 1} {node4 1}} node4 {{node1 1} {node3 1}}"
#Test 1.2 - directed, weighted graph with different wages at crucial edges ( e.g. edges between same nodes )
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.2 { AdjacencyList, directed, weighted, graph simulation } {
SETUP_ADJACENCYLIST_K4_WEIGHTED_DIRECTED
set result [adjsort [struct::graph::op::toAdjacencyList mygraph -directed -weights]]
mygraph destroy
set result
} {node1 {{node2 1} {node3 1} {node4 2}} node2 {{node3 1}} node3 {{node4 1}} node4 {{node1 3}}}
#Test 1.3 - directed weighted graph, same us upper but changed order of options
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.3 { AdjacencyList, directed, weighted, graph simulation } {
SETUP_ADJACENCYLIST_K4_WEIGHTED_DIRECTED
set result [adjsort [struct::graph::op::toAdjacencyList mygraph -weights -directed]]
mygraph destroy
set result
} {node1 {{node2 1} {node3 1} {node4 2}} node2 {{node3 1}} node3 {{node4 1}} node4 {{node1 3}}}
#Test 1.4 - directed but unweighted graph containing some special cases
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.4 { AdjacencyList, directed, unweighted, graph simulation } {
SETUP_ADJACENCYLIST_K4
set result [adjsort [struct::graph::op::toAdjacencyList mygraph -directed]]
mygraph destroy
set result
} {node1 {node2 node3 node4} node2 node3 node3 node4 node4 node1}
#Test 1.5 - case where graph has no edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.5 { AdjacencyList, no edges } {
SETUP_NOEDGES_1
set result [struct::graph::op::toAdjacencyList mygraph]
mygraph destroy
set result
} "node1 {} node2 {} node3 {} node4 {}"
#Test 1.6 - case where graph has no edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.6 { AdjacencyList, no edges } {
SETUP_NOEDGES_1
set result [struct::graph::op::toAdjacencyList mygraph -directed -weights]
mygraph destroy
set result
} "node1 {} node2 {} node3 {} node4 {}"
#Test 1.7 - another graph simulation for checking proper return value
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-1.7 { AdjacencyList, undirected, unweighted, graph simulation } {
SETUP_ADJACENCYLIST_1
set result [struct::graph::op::toAdjacencyList mygraph]
mygraph destroy
set result
} "node1 {node2 node6} node2 {node1 node3} node3 {node2 node6} node4 {node5 node6} node5 node4 node6 {node1 node3 node4}"
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-2.0 { AdjacencyList, wrong args, missing } {
catch {struct::graph::op::toAdjacencyList} msg
set msg
} [tcltest::wrongNumArgs struct::graph::op::toAdjacencyList {G args} 0]
# -------------------------------------------------------------------------
# Logical arguments checks and failures
#Test 3.0 - case when given undirected graph doesn't have weights at all edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.0 {AdjacencyList, undirected, lack of weights at edges } {
SETUP_UNWEIGHTED_K4
catch {struct::graph::op::toAdjacencyList mygraph -weights} result
mygraph destroy
set result
} [UnweightedArcOccurance]
#Test 3.1 - case when given directed graph doesn't have weights at all edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.1 {AdjacencyList, directed, lack of weights at edges } {
SETUP_UNWEIGHTED_K4
catch {struct::graph::op::toAdjacencyList mygraph -directed -weights} result
mygraph destroy
set result
} [UnweightedArcOccurance]
#Test 3.2 - case when given undirected graph doesn't have weights at some edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.2 {AdjacencyList, undirected, partial lack of weights at edges } {
SETUP_PARTIALLYWEIGHTED_K4
catch {struct::graph::op::toAdjacencyList mygraph -weights} result
mygraph destroy
set result
} [UnweightedArcOccurance]
#Test 3.3 - case when given directed graph doesn't have weights at some edges
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.3 {AdjacencyList, directed, partial lack of weights at edges } {
SETUP_PARTIALLYWEIGHTED_K4
catch {struct::graph::op::toAdjacencyList mygraph -directed -weights} result
mygraph destroy
set result
} [UnweightedArcOccurance]
#Test 3.4 - case when user sets wrong option to the procedure
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.4 {AdjacencyList, bad option used } {
SETUP
catch {struct::graph::op::toAdjacencyList mygraph -badoption} result
mygraph destroy
set result
} {Bad option "-badoption". Expected -directed or -weights}
#Test 3.5 - case when user sets wrong option to the procedure
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.5 {AdjacencyList, bad options used } {
SETUP
catch {struct::graph::op::toAdjacencyList mygraph -directed -badoption} result
mygraph destroy
set result
} {Bad option "-badoption". Expected -directed or -weights}
#Test 3.6 - case when user sets wrong option to the procedure
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.6 {AdjacencyList, bad options used } {
SETUP
catch {struct::graph::op::toAdjacencyList mygraph -weights -badoption} result
mygraph destroy
set result
} {Bad option "-badoption". Expected -directed or -weights}
#Test 3.7 - case when user sets wrong option to the procedure
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.7 {AdjacencyList, bad options used } {
SETUP
catch {struct::graph::op::toAdjacencyList mygraph -badoption -directed} result
mygraph destroy
set result
} {Bad option "-badoption". Expected -directed or -weights}
#Test 3.8 - case when user sets wrong option to the procedure
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-AdjacencyList-3.8 {AdjacencyList, bad options used } {
SETUP
catch {struct::graph::op::toAdjacencyList mygraph -badoption -weights} result
mygraph destroy
set result
} {Bad option "-badoption". Expected -directed or -weights}
|