File: disjointset.test

package info (click to toggle)
tcllib 1.12-dfsg-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 25,336 kB
  • ctags: 7,235
  • sloc: tcl: 126,727; ansic: 10,090; sh: 9,855; xml: 1,766; yacc: 753; makefile: 127; perl: 84; f90: 84; pascal: 74; python: 33; ruby: 13; php: 11
file content (116 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (5)
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
# -*- tcl -*-
# Test procedures for the disjoint set structure implementation
# Author: Alejandro Eduardo Cruz Paz
# 5 August 2008

package require tcltest
source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.4
testsNeedTcltest 1.0

support {
    useAccel [useTcllibC] struct/sets.tcl struct::set
    TestAccelInit                         struct::set
}
testing {
    useLocal disjointset.tcl struct::disjointset
}

############################################################
# Helper functions
# - Create a disjoint set of many partitions.
# - Sort a set of partitions into a canonical order for comparison.

proc testset {} {
    ::struct::disjointset DS
    DS add-partition {1 2 3 4}
    DS add-partition {5 6}
    DS add-partition 0
    DS add-partition {9 8}
    DS add-partition {10 7}
    return
}

proc canonset {partitions} {
    set res {}
    foreach x $partitions {
	lappend res [lsort -dict $x]
    }
    return [lsort -dict $res]
}

proc djstate {ds} {
    list [canonset [$ds partitions]] [$ds num-partitions]
}

############################################################
## Iterate over all loaded implementations, activate
## them in turn, and run the tests for the active
## implementation.

TestAccelDo struct::set impl {
    # The global variable 'impl' is part of the public
    # API the testsuite (in set.testsuite) can expect
    # from the environment.

    switch -exact -- $impl {
	critcl {
	    if {[package vsatisfies [package present Tcl] 8.5]} {
		proc tmWrong {m loarg n} {
		    return [tcltest::wrongNumArgs "struct::disjointset $m" $loarg $n]
		}

		proc tmTooMany {m loarg} {
		    return [tcltest::tooManyArgs "struct::disjointset $m" $loarg]
		}

		proc Nothing {} {
		    return [tcltest::wrongNumArgs {struct::disjointset} {cmd ?arg ...?} 0]
		}
	    } else {
		proc tmWrong {m loarg n} {
		    return [tcltest::wrongNumArgs "::struct::disjointset $m" $loarg $n]
		}

		proc tmTooMany {m loarg} {
		    return [tcltest::tooManyArgs "::struct::disjointset $m" $loarg]
		}

		proc Nothing {} {
		    return [tcltest::wrongNumArgs {::struct::disjointset} {cmd ?arg ...?} 0]
		}
	    }
	}
	tcl {
	    if {[package vsatisfies [package present Tcl] 8.5]} {
		# In 8.5 head the alias itself is reported, not what it
		# resolved to.
		proc Nothing {} {
		    return [tcltest::wrongNumArgs struct::disjointset {cmd args} 0]
		}
	    } else {
		proc Nothing {} {
		    return [tcltest::wrongNumArgs {::struct::disjointset} {cmd args} 0]
		}
	    }

	    proc tmWrong {m loarg n} {
		return [tcltest::wrongNumArgs "::struct::disjointset::S_$m" $loarg $n]
	    }

	    proc tmTooMany {m loarg} {
		return [tcltest::tooManyArgs "::struct::disjointset::S_$m" $loarg]
	    }
	}
    }

    source [localPath disjointset.testsuite]
}

############################################################
TestAccelExit struct::set

testsuiteCleanup