1# -*- tcl -*-
2# Graph tests - graph command basics
3# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
4# All rights reserved.
5# RCS: @(#) $Id: command.test,v 1.7 2009/11/26 04:42:16 andreas_kupries Exp $
6
7# -------------------------------------------------------------------------
8# Wrong # args: Missing, Too many
9
10# Graph class command has no missing arguments, will auto-generate
11# instance name. As for too many arguments, this will be checked as
12# part of testing the de-serialization.
13
14test graph-${impl}-${setimpl}-create-1.1 {graph create, copy, wrong#args, missing} {
15    catch {mygraph destroy}
16    catch {struct::graph mygraph =} result
17    set result
18} {wrong # args: should be "struct::graph ?name ?=|:=|as|deserialize source??"}
19
20test graph-${impl}-${setimpl}-create-1.2 {graph create, copy, wrong#args, too many} {
21    catch {mygraph destroy}
22    catch {struct::graph mygraph = a b} result
23    set result
24} {wrong # args: should be "struct::graph ?name ?=|:=|as|deserialize source??"}
25
26test graph-${impl}-${setimpl}-create-1.3 {graph create, copy, unknown operator} {
27    catch {mygraph destroy}
28    catch {struct::graph mygraph foo a} result
29    set result
30} {wrong # args: should be "struct::graph ?name ?=|:=|as|deserialize source??"}
31
32# -------------------------------------------------------------------------
33# Logical arguments checks and failures
34
35test graph-${impl}-${setimpl}-create-2.0 {graph create, duplicate, graph} {
36    SETUP
37    catch {struct::graph mygraph} msg
38    mygraph destroy
39    set msg
40} "command \"::mygraph\" already exists, unable to create graph"
41
42test graph-${impl}-${setimpl}-create-2.1 {graph create, duplicate, non-graph} {
43    catch {struct::graph set} msg
44    set msg
45} "command \"::set\" already exists, unable to create graph"
46
47# -------------------------------------------------------------------------
48# Ok arguments.
49
50test graph-${impl}-${setimpl}-create-3.0 {graph create, object command is created} {
51    SETUP
52    set result [string equal [info commands ::mygraph] "::mygraph"]
53    mygraph destroy
54    set result
55} 1
56
57test graph-${impl}-${setimpl}-create-3.1 {graph create, auto-generation of name} {
58    set name [struct::graph]
59    set result [list \
60	    [string match ::graph* $name] \
61	    [string equal [info commands $name] "$name"]]
62    $name destroy
63    set result
64} {1 1}
65
66test graph-${impl}-${setimpl}-create-3.2 {graph create, destroy removes object command} {
67    SETUP
68    mygraph destroy
69    string equal [info commands ::mygraph] ""
70} 1
71
72test graph-${impl}-${setimpl}-create-3.3 {graph create, copy, value} {
73    catch {mygraph destroy}
74    set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
75
76    struct::graph mygraph deserialize $serial
77    set result [validate_serial mygraph $serial]
78    mygraph destroy
79
80    set result
81} ok
82
83test graph-${impl}-${setimpl}-create-3.4 {graph create, copy, graph} {
84    catch {mygraph destroy}
85    set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
86
87    struct::graph mygraph deserialize $serial
88    struct::graph bgraph = mygraph
89
90    set result [validate_serial bgraph $serial]
91    mygraph destroy
92    bgraph  destroy
93
94    set result
95} ok
96
97test graph-${impl}-${setimpl}-create-3.5 {graph create, copy, graph with weights} {
98    catch {mygraph destroy}
99    set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {} 222}} %1 {} {{d 9 {}}} %2 {} {{e 0 {} 444}} {data foo}}
100
101    struct::graph mygraph deserialize $serial
102    struct::graph bgraph = mygraph
103
104    set result [validate_serial bgraph $serial]
105    mygraph destroy
106    bgraph  destroy
107
108    set result
109} ok
110
111test graph-${impl}-${setimpl}-create-3.6 {graph create, copy, empty graph} {
112    catch {mygraph destroy}
113    set serial {{}}
114
115    struct::graph mygraph deserialize $serial
116    struct::graph bgraph = mygraph
117
118    set result [validate_serial bgraph $serial]
119    mygraph destroy
120    bgraph  destroy
121
122    set result
123} ok
124
125# -------------------------------------------------------------------------
126# Wrong # args: Missing, Too many
127
128test graph-${impl}-${setimpl}-instance-1.0 {graph command, wrong#args, missing} {
129    SETUP
130    catch {mygraph} msg
131    mygraph destroy
132    set msg
133} "wrong # args: should be \"$MY option ?arg arg ...?\""
134
135# Too many arguments dependent on method, not testable here.
136
137# -------------------------------------------------------------------------
138# Logical arguments checks and failures
139
140test graph-${impl}-${setimpl}-instance-2.0 {graph command, bad method} {
141    SETUP
142    catch {mygraph foo} msg
143    mygraph destroy
144    set msg
145} {bad option "foo": must be -->, =, append, arc, arcs, deserialize, destroy, get, getall, keyexists, keys, lappend, node, nodes, serialize, set, swap, unset, or walk}
146
147test graph-${impl}-${setimpl}-instance-2.1 {graph arc command, bad method} {
148    SETUP
149    catch {mygraph arc foo} msg
150    mygraph destroy
151    set msg
152} {bad option "foo": must be append, attr, delete, exists, flip, get, getall, getunweighted, getweight, hasweight, insert, keyexists, keys, lappend, move, move-source, move-target, nodes, rename, set, setunweighted, setweight, source, target, unset, unsetweight, or weights}
153
154test graph-${impl}-${setimpl}-instance-2.2 {graph node command, bad method} {
155    SETUP
156    catch {mygraph node foo} msg
157    mygraph destroy
158    set msg
159} {bad option "foo": must be append, attr, degree, delete, exists, get, getall, insert, keyexists, keys, lappend, opposite, rename, set, or unset}
160
161# -------------------------------------------------------------------------
162