# -*- tcl -*- # Graph tests - serialize # Copyright (c) 2006 Andreas Kupries # 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 # -------------------------------------------------------------------------