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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
# -*- tcl -*-
#Edmonds Karp algorithm - computing maximum flow in a flow network
#
# ------------------------------------------------------------------------------------
# Tests concerning returning right values by algorithm
# ------------------------------------------------------------------------------------
#Test 1.0
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.0 { graph simulation } {
SETUP_FORDFULKERSON_1
set result [dictsort [struct::graph::op::FordFulkerson mygraph s t]]
mygraph destroy
set result
} {{s v1} 12 {s v2} 11 {v1 v3} 12 {v2 v4} 11 {v3 t} 19 {v4 t} 4 {v4 v3} 7}
#Test 1.1
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.1 { graph simulation } {
SETUP_FORDFULKERSON_2
set result [dictsort [struct::graph::op::FordFulkerson mygraph a d]]
mygraph destroy
set result
} {{a b} 1000000 {a c} 1000000 {b d} 1000000 {c d} 1000000}
#Test 1.2
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.2 { graph simulation } {
SETUP_FORDFULKERSON_3
set result [dictsort [struct::graph::op::FordFulkerson mygraph s t]]
mygraph destroy
set result
} {{s v1} 6 {s v2} 5 {s v3} 3 {v1 t} 3 {v1 v2} 3 {v2 t} 8 {v3 t} 3}
#Test 1.3
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.3 { graph simulation } {
SETUP_FORDFULKERSON_4
set result [dictsort [struct::graph::op::FordFulkerson mygraph s t]]
mygraph destroy
set result
} {{s v1} 4 {s v2} 5 {s v3} 3 {v1 t} 3 {v1 v2} 1 {v2 t} 6 {v3 t} 3}
#Test 1.4
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.4 { graph simulation } {
SETUP_FORDFULKERSON_5
set result [dictsort [struct::graph::op::FordFulkerson mygraph s t]]
mygraph destroy
set result
} {{s v1} 6.5 {s v2} 5.5 {s v3} 3.5 {v1 t} 3.1 {v1 v2} 3.4000000000000004 {v2 t} 8.9 {v3 t} 3.5}
#Test 1.5
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.5 { graph simulation } -setup {
SETUP_FORDFULKERSON_1
set output {}
foreach arc [mygraph arcs] {
set u [mygraph arc source $arc]
set v [mygraph arc target $arc]
dict set f [list $u $v] 0
dict set f [list $v $u] 0
}
} -body {
set result [struct::graph::op::createResidualGraph mygraph $f]
foreach arc [$result arcs] {
set throughput [$result arc get $arc throughput]
if { $throughput } {
dict set output $arc $throughput
}
}
dictsort $output
} -cleanup {
unset throughput output f arc u v
$result destroy
mygraph destroy
} -result {{s v1} 16 {s v2} 13 {v1 v2} 10 {v1 v3} 12 {v2 v1} 4 {v2 v4} 14 {v3 t} 20 {v3 v2} 9 {v4 t} 4 {v4 v3} 7}
#Test 1.6
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.6 { graph simulation } -setup {
SETUP_FORDFULKERSON_1
set output {}
set f [SETUP_FLOWS_1 mygraph]
} -body {
set result [struct::graph::op::createResidualGraph mygraph $f]
foreach arc [$result arcs] {
set throughput [$result arc get $arc throughput]
if { $throughput } {
dict set output $arc $throughput
}
}
dictsort $output
} -cleanup {
unset throughput output f arc
$result destroy
mygraph destroy
} -result {{s v1} 12 {s v2} 13 {t v4} 4 {v1 s} 4 {v1 v2} 10 {v1 v3} 8 {v2 v1} 4 {v2 v3} 4 {v2 v4} 10 {v3 t} 20 {v3 v1} 4 {v3 v2} 5 {v4 v2} 4 {v4 v3} 7}
#Test 1.7
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.7 { graph simulation } -setup {
SETUP_FORDFULKERSON_1
set output {}
set f [SETUP_FLOWS_2 mygraph]
} -body {
set result [struct::graph::op::createResidualGraph mygraph $f]
foreach arc [$result arcs] {
set throughput [$result arc get $arc throughput]
if { $throughput } {
dict set output $arc $throughput
}
}
dictsort $output
} -cleanup {
unset throughput output f arc
$result destroy
mygraph destroy
} -result {{s v1} 5 {s v2} 13 {t v3} 7 {t v4} 4 {v1 s} 11 {v1 v2} 3 {v1 v3} 8 {v2 v1} 11 {v2 v3} 4 {v2 v4} 3 {v3 t} 13 {v3 v1} 4 {v3 v2} 5 {v3 v4} 7 {v4 v2} 11}
#Test 1.8
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.8 { graph simulation } -setup {
SETUP_FORDFULKERSON_1
set output {}
set f [SETUP_FLOWS_3 mygraph]
} -body {
set result [struct::graph::op::createResidualGraph mygraph $f]
foreach arc [$result arcs] {
set throughput [$result arc get $arc throughput]
if { $throughput } {
dict set output $arc $throughput
}
}
dictsort $output
} -cleanup {
unset throughput output f arc
$result destroy
mygraph destroy
} -result {{s v1} 5 {s v2} 5 {t v3} 15 {t v4} 4 {v1 s} 11 {v1 v2} 11 {v2 s} 8 {v2 v1} 3 {v2 v3} 4 {v2 v4} 3 {v3 t} 5 {v3 v1} 12 {v3 v2} 5 {v3 v4} 7 {v4 v2} 11}
#Test 1.9
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-1.9 { graph simulation } -setup {
SETUP_FORDFULKERSON_1
set output {}
set f [SETUP_FLOWS_4 mygraph]
} -body {
set result [struct::graph::op::createResidualGraph mygraph $f]
foreach arc [$result arcs] {
set throughput [$result arc get $arc throughput]
if { $throughput } {
dict set output $arc $throughput
}
}
dictsort $output
} -cleanup {
unset throughput output f arc
$result destroy
mygraph destroy
} -result {{s v1} 5 {s v2} 1 {t v3} 19 {t v4} 4 {v1 s} 11 {v1 v2} 11 {v2 s} 12 {v2 v1} 3 {v2 v4} 3 {v3 t} 1 {v3 v1} 12 {v3 v2} 9 {v3 v4} 7 {v4 v2} 11}
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-2.0 { FordFulkerson, wrong args, missing } {
catch {struct::graph::op::FordFulkerson} msg
set msg
} [tcltest::wrongNumArgs struct::graph::op::FordFulkerson {G s t} 0]
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-2.1 { FordFulkerson, wrong args, missing } {
catch {struct::graph::op::FordFulkerson G} msg
set msg
} [tcltest::wrongNumArgs struct::graph::op::FordFulkerson {G s t} 1]
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-2.2 { FordFulkerson, wrong args, missing } {
catch {struct::graph::op::FordFulkerson G s} msg
set msg
} [tcltest::wrongNumArgs struct::graph::op::FordFulkerson {G s t} 2]
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-2.3 { FordFulkerson, wrong args, too many} {
catch {struct::graph::op::FordFulkerson G s t z} msg
set msg
} [tcltest::tooManyArgs struct::graph::op::FordFulkerson {G s t}]
# -------------------------------------------------------------------------
# Logical arguments checks and failures
#Test 3.0 - case when sink and source nodes given at input aren't nodes of input graph
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-3.0 {FordFulkerson, wrong sink or source } {
SETUP_FORDFULKERSON_1
catch {struct::graph::op::FordFulkerson mygraph a b } result
mygraph destroy
set result
} [LackOfSinkOrSource a b]
#Test 3.1 - case when input network has lacking attributes
test graphop-t${treeimpl}-g${impl}-s${setimpl}-st${stkimpl}-q${queimpl}-FordFulkerson-3.1 {FordFulkerson, missing attributes } {
SETUP_BUSACKERGOWEN_2
catch {struct::graph::op::FordFulkerson mygraph s t } result
mygraph destroy
set result
} [WrongAttributes throughput]
|