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
  
     | 
    
      # -*- tcl -*-
# Graph tests - swap
# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# RCS: @(#) $Id: swap.test,v 1.2 2007/04/12 03:01:55 andreas_kupries Exp $
# Syntax: graph swap NODE-1 NODE-2
# -------------------------------------------------------------------------
# Wrong # args: Missing, Too many
test graph-${impl}-${setimpl}-swap-1.0 {swap, wrong#args, missing} {
    SETUP
    catch {mygraph swap} msg
    mygraph destroy
    set msg
} [tmWrong swap {node1 node2} 0]
test graph-${impl}-${setimpl}-swap-1.1 {swap, wrong#args, missing} {
    SETUP
    catch {mygraph swap a} msg
    mygraph destroy
    set msg
} [tmWrong swap {node1 node2} 1]
test graph-${impl}-${setimpl}-swap-1.2 {swap, wrong#args, too many} {
    SETUP
    catch {mygraph swap a b c} msg
    mygraph destroy
    set msg
} [tmTooMany swap {node1 node2}]
# -------------------------------------------------------------------------
# Logical arguments checks and failures
test graph-${impl}-${setimpl}-swap-2.0 {swap, missing node} {
    SETUP
    mygraph node insert       node1
    catch {mygraph swap node0 node1} msg
    mygraph destroy
    set msg
} [MissingNode $MY node0]
test graph-${impl}-${setimpl}-swap-2.1 {swap, missing node} {
    SETUP
    mygraph node insert node0
    catch {mygraph swap node0 node1} msg
    mygraph destroy
    set msg
} [MissingNode $MY node1]
test graph-${impl}-${setimpl}-swap-2.2 {swap, self} {
    SETUP
    mygraph node insert node0
    catch {mygraph swap node0 node0} msg
    mygraph destroy
    set msg
} "cannot swap node \"node0\" with itself"
# -------------------------------------------------------------------------
# Ok arguments.
proc SETUP_2 {} {
    #             +--/a4/-> n4
    #             |
    # n0 -/a1/-> n1 -/a3/-> n3
    #  |
    #  +--/a2/-> n2
    mygraph node insert n0 n1 n2 n3 n4
    mygraph arc  insert n0 n1 a1
    mygraph arc  insert n0 n2 a2
    mygraph arc  insert n1 n3 a3
    mygraph arc  insert n1 n4 a4
    return
}
test graph-${impl}-${setimpl}-swap-3.0 {swap, node relationships} {
    SETUP
    SETUP_2
    mygraph swap n0 n1
    set     result {}
    lappend result [lsort [mygraph nodes -out n0]]
    lappend result [lsort [mygraph nodes -out n1]]
    mygraph destroy
    set result
} {{n3 n4} {n0 n2}}
test graph-${impl}-${setimpl}-swap-3.1 {swap, node relationships} {
    SETUP
    SETUP_2
    mygraph swap n0 n3
    set     result {}
    lappend result [lsort [mygraph nodes -out n0]]
    lappend result [lsort [mygraph nodes -out n3]]
    mygraph destroy
    set result
} {{} {n1 n2}}
test graph-${impl}-${setimpl}-swap-3.2 {swap, node relationships} {
    SETUP
    SETUP_2
    mygraph swap n1 n0
    set     result {}
    lappend result [lsort [mygraph nodes -out n0]]
    lappend result [lsort [mygraph nodes -out n1]]
    mygraph destroy
    set result
} {{n3 n4} {n0 n2}}
# -------------------------------------------------------------------------
 
     |