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
|
# -*- tcl -*-
# Graph tests - serialize
# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# RCS: @(#) $Id: serialize.test,v 1.3 2008/10/11 23:23:48 andreas_kupries Exp $
# Syntax: graph serialize ?NODE...?
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
# Cannot have missing arguments, nor too many.
# -------------------------------------------------------------------------
# Logical arguments checks and failures
test graph-${impl}-${setimpl}-serialize-1.0 {serialize, missing node} {
SETUP
catch {mygraph serialize foo} result
mygraph destroy
set result
} [MissingNode $MY foo]
# -------------------------------------------------------------------------
# Ok arguments.
test graph-${impl}-${setimpl}-serialize-2.0 {serialize, empty graph} {
SETUP
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial = {{}}
} ok
test graph-${impl}-${setimpl}-serialize-2.1 {serialize, complete graph} {
SETUP
mygraph node insert %0 %1 %2 %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
mygraph set data foo
mygraph node set %0 foo bar
mygraph arc set b bar snarf
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial =
# %3 {} { /0
# {f 6 {}}
# }
# %0 {foo bar} { /3
# {a 6 {}}
# {b 9 {bar snarf}}
# {c 0 {}}
# }
# %1 {} { /6
# {d 9 {}}
# }
# %2 {} { /9
# {e 0 {}}
# }
# {data foo}
} ok
test graph-${impl}-${setimpl}-serialize-2.2 {serialize, complete graph, no attributes} {
SETUP
mygraph node insert %0 %1 %2 %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial =
# %3 {} { /0
# {f 6 {}}
# }
# %0 {} { /3
# {a 6 {}}
# {b 9 {}}
# {c 0 {}}
# }
# %1 {} { /6
# {d 9 {}}
# }
# %2 {} { /9
# {e 0 {}}
# }
# {}
} ok
test graph-${impl}-${setimpl}-serialize-2.3 {serialize, subgraph} {
SETUP
mygraph node insert %0 %1 %2 %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
mygraph set data foo
mygraph node set %0 foo bar
mygraph arc set b bar snarf
set serial [mygraph serialize %0 %1 %3]
set result [validate_serial mygraph $serial {%0 %1 %3}]
mygraph destroy
set result
# serial =
# %0 {foo bar} {{a 3 {}} {c 6 {}}} /0
# %1 {} {} /3
# %3 {} {{f 3 {}}} /6
# {data foo}
} ok
test graph-${impl}-${setimpl}-serialize-2.4 {serialize, subgraph, duplicate nodes} {
SETUP
mygraph node insert %0 %1 %2 %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
mygraph set data foo
mygraph node set %0 foo bar
mygraph arc set b bar snarf
set serial [mygraph serialize %0 %1 %3 %0]
set result [validate_serial mygraph $serial {%0 %1 %3}]
mygraph destroy
set result
# serial =
# %0 {foo bar} {{a 3 {}} {c 6 {}}} /0
# %1 {} {} /3
# %3 {} {{f 3 {}}} /6
# {data foo}
} ok
test graph-${impl}-${setimpl}-serialize-2.5 {serialize, complete graph, some weights} {
SETUP
mygraph node insert %0 %1 %2 %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d ; mygraph arc setweight d 100
mygraph arc insert %2 %3 e ; mygraph arc setweight e 200
mygraph arc insert %3 %1 f ; mygraph arc setweight f 400
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial =
# %3 {} { /0
# {f 6 {} 400}
# }
# %0 {} { /3
# {a 6 {}}
# {b 9 {}}
# {c 0 {}}
# }
# %1 {} { /6
# {d 9 {} 100}
# }
# %2 {} { /9
# {e 0 {} 200}
# }
# {}
} ok
# -------------------------------------------------------------------------
|