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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
# -*- tcl -*-
# Graph tests - arcs
# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# RCS: @(#) $Id: arcs.test,v 1.4 2009/11/03 17:38:30 andreas_kupries Exp $
# Syntax: graph arcs
# (1) graph arcs -key KEY
# graph arcs -key KEY -value VALUE
# (2) graph arcs -filter CMDPREFIX
# (3) graph arcs -in NODE...
# graph arcs -out NODE...
# graph arcs -adj NODE...
# graph arcs -inner NODE...
# graph arcs -embedded NODE...
# We can use one in each group (1,2,3)
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
# Cannot have missing arguments (zero is fine),
# except when switches are in use. That however
# is tested with the switches. Ditto for too many
# arguments.
# -------------------------------------------------------------------------
# Logical arguments checks and failures
test graph-${impl}-${setimpl}-arcs-1.0 {arcs, bad switch} {
SETUP
catch {mygraph arcs -foo} msg
mygraph destroy
set msg
} {bad restriction "-foo": must be -adj, -embedding, -filter, -in, -inner, -key, -out, or -value}
# -------------------------------------------------------------------------
# Ok arguments.
test graph-${impl}-${setimpl}-arcs-2.0 {arcs, empty graph} {
SETUP
set result [mygraph arcs]
mygraph destroy
set result
} {}
test graph-${impl}-${setimpl}-arcs-2.1 {arcs, nodes without arcs} {
SETUP
mygraph node insert 0 1 2 3 4 5
set result [mygraph arcs]
mygraph destroy
set result
} {}
test graph-${impl}-${setimpl}-arcs-2.2 {arcs} {
SETUP
mygraph node insert 0 1 2 3 4 5
mygraph arc insert 0 1 a
mygraph arc insert 2 3 b
mygraph arc insert 4 5 c
set result [lsort [mygraph arcs]]
mygraph destroy
set result
} {a b c}
# ---------------------------------------------------
# (1) -key, -value
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
test graph-${impl}-${setimpl}-arcs-key-1.0 {arcs, wrong#args, missing} {
SETUP
catch {mygraph arcs -key} msg
mygraph destroy
set msg
} "wrong # args: should be \"$MY arcs ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?\""
test graph-${impl}-${setimpl}-arcs-key-1.1 {arcs, wrong#args, missing} {
SETUP
catch {mygraph arcs -value} msg
mygraph destroy
set msg
} "wrong # args: should be \"$MY arcs ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?\""
# -------------------------------------------------------------------------
# Logical arguments checks and failures
test graph-${impl}-${setimpl}-arcs-key-2.0 {arcs, multiple -key} {
SETUP
catch {mygraph arcs -key foobar -value 1 -key foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-key"}
test graph-${impl}-${setimpl}-arcs-key-2.1 {arcs, multiple -value} {
SETUP
catch {mygraph arcs -key foobar -value 1 -value foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-value"}
test graph-${impl}-${setimpl}-arcs-key-2.2 {arcs, -value without -key} {
SETUP
catch {mygraph arcs -value 1} msg
mygraph destroy
set msg
} {invalid restriction: use of "-value" without "-key"}
# -------------------------------------------------------------------------
# Ok arguments.
test graph-${impl}-${setimpl}-arcs-key-3.0 {arcs, -key} {
SETUP
mygraph node insert n0 n1
mygraph arc insert n0 n1 a1
mygraph arc insert n0 n1 a2
mygraph arc set a1 foobar 1
mygraph arc set a2 blubber 2
catch {mygraph arcs -key foobar} msg
mygraph destroy
set msg
} a1
test graph-${impl}-${setimpl}-arcs-key-3.1 {arcs, -key, -value} {
SETUP
mygraph node insert n0 n1
mygraph arc insert n0 n1 a1
mygraph arc insert n0 n1 a2
mygraph arc set a1 foobar 1
mygraph arc set a2 foobar 2
catch {mygraph arcs -key foobar -value 1} msg
mygraph destroy
set msg
} a1
# ---------------------------------------------------
# (2) -filter
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
test graph-${impl}-${setimpl}-arcs-filter-1.0 {arcs, wrong#args, missing} {
SETUP
catch {mygraph arcs -filter} msg
mygraph destroy
set msg
} "wrong # args: should be \"$MY arcs ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?\""
# -------------------------------------------------------------------------
# Logical arguments checks and failures
test graph-${impl}-${setimpl}-arcs-filter-2.0 {arcs, multiple -filter} {
SETUP
catch {mygraph arcs -filter foobar -filter foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-filter"}
# -------------------------------------------------------------------------
# Ok arguments.
test graph-${impl}-${setimpl}-arcs-filter-3.0 {arcs, -filter} {
SETUP
mygraph node insert 1 2 3 4 5 6
mygraph arc insert 4 1 A
mygraph arc insert 5 2 B
mygraph arc insert 6 3 C
mygraph arc insert 3 1 D
mygraph arc insert 1 2 E
mygraph arc insert 2 3 F
mygraph arc set A volume 30
mygraph arc set C volume 50
proc vol {g n} {
$g arc keyexists $n volume
}
set result [lsort [mygraph arcs -filter vol]]
mygraph destroy
rename vol {}
set result
} {A C}
test graph-${impl}-${setimpl}-arcs-filter-3.1 {arcs, -filter} {
SETUP
mygraph node insert 1 2 3 4 5 6
mygraph arc insert 4 1 A
mygraph arc insert 5 2 B
mygraph arc insert 6 3 C
mygraph arc insert 3 1 D
mygraph arc insert 1 2 E
mygraph arc insert 2 3 F
mygraph arc set A volume 30
mygraph arc set C volume 50
proc vol {g n} {
if {![$g arc keyexists $n volume]} {return 0}
expr {[$g arc get $n volume] > 40}
}
set result [mygraph arcs -filter vol]
mygraph destroy
rename vol {}
set result
} C
# ---------------------------------------------------
# (3) -in, -out, -adj, -inner, -embedding
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
set n 0
foreach switch {-in -out -adj -inner -embedding} {
test graph-${impl}-${setimpl}-arcs-ioaie-1.$n "arcs, $switch, wrong#args, missing" {
SETUP
catch {mygraph arcs $switch} msg
mygraph destroy
set msg
} "wrong # args: should be \"$MY arcs ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?\"" ; # {}
incr n
}
unset n
# -------------------------------------------------------------------------
# Logical arguments checks and failures
set n 0
foreach switch {-in -out -adj -inner -embedding} {
test graph-${impl}-${setimpl}-arcs-ioaie-2.$n "arcs, $switch, missing node" {
SETUP
catch {mygraph arcs $switch x} msg
mygraph destroy
set msg
} [MissingNode $MY x] ; # {}
incr n
foreach switchB {-in -out -adj -inner -embedding} {
test graph-${impl}-${setimpl}-arcs-ioaie-2.$n "arcs, $switch, $switchB together" {
SETUP
catch {mygraph arcs $switch $switchB x} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"} ; # {}
incr n
}
}
unset n
# -------------------------------------------------------------------------
# Ok arguments.
set n 0
foreach {switch nodes expected} {
-in {1 2 3} {A B C D E F} -in {4 5 6} {}
-out {1 2 3} {D E F} -out {4 5 6} {A B C}
-adj {1 2 3} {A B C D E F} -adj {4 5 6} {A B C}
-inner {1 2 3} {D E F} -inner {4 5 6} {}
-embedding {1 2 3} {A B C} -embedding {4 5 6} {A B C}
-in {1 2} {A B D E} -in {4 5} {}
-out {1 2} {E F} -out {4 5} {A B}
-adj {1 2} {A B D E F} -adj {4 5} {A B}
-inner {1 2} {E} -inner {4 5} {}
-embedding {1 2} {A B D F} -embedding {4 5} {A B}
-in {1} {A D} -in {4} {}
-out {1} {E} -out {4} {A}
-adj {1} {A D E} -adj {4} {A}
-inner {1} {} -inner {4} {}
-embedding {1} {A D E} -embedding {4} {A}
-in {1 4} {A D} -in {4 2} {B E}
-out {1 4} {A E} -out {4 2} {A F}
-adj {1 4} {A D E} -adj {4 2} {A B E F}
-inner {1 4} {A} -inner {4 2} {}
-embedding {1 4} {D E} -embedding {4 2} {A B E F}
-in {1 1} {A D} -in {4 4} {}
-out {1 1} {E} -out {4 4} {A}
-adj {1 1} {A D E} -adj {4 4} {A}
-inner {1 1} {} -inner {4 4} {}
-embedding {1 1} {A D E} -embedding {4 4} {A}
} {
test graph-${impl}-${setimpl}-arcs-ioaie-3.$n "arcs, $switch" {
SETUP
mygraph node insert 1 2 3 4 5 6
mygraph arc insert 4 1 A
mygraph arc insert 5 2 B
mygraph arc insert 6 3 C
mygraph arc insert 3 1 D
mygraph arc insert 1 2 E
mygraph arc insert 2 3 F
set result [lsort [eval [linsert $nodes 0 mygraph arcs $switch]]]
mygraph destroy
set result
} $expected ; # {}
incr n
}
unset n
test graph-${impl}-${setimpl}-arcs-adj-1.0 {arcs -adj, border case C code failure} -setup {
struct::graph mygraph
mygraph node insert E
mygraph node insert F
mygraph arc insert E F E_F
} -body {
mygraph arcs -adj E
} -cleanup {
mygraph destroy
} -result {E_F}
# ---------------------------------------------------
|