OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [cmdIL.test] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file contains a collection of tests for the procedures in the
2
# file tclCmdIL.c.  Sourcing this file into Tcl runs the tests and
3
# generates output for errors.  No output means no errors were found.
4
#
5
# Copyright (c) 1997 Sun Microsystems, Inc.
6
# Copyright (c) 1998 by Scriptics Corporation.
7
#
8
# See the file "license.terms" for information on usage and redistribution
9
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
#
11
# RCS: @(#) $Id: cmdIL.test,v 1.1.1.1 2002-01-16 10:25:35 markom Exp $
12
 
13
if {[string compare test [info procs test]] == 1} then {source defs}
14
 
15
test cmdIL-1.1 {Tcl_LsortObjCmd procedure} {
16
    list [catch {lsort} msg] $msg
17
} {1 {wrong # args: should be "lsort ?options? list"}}
18
test cmdIL-1.2 {Tcl_LsortObjCmd procedure} {
19
    list [catch {lsort -foo {1 3 2 5}} msg] $msg
20
} {1 {bad option "-foo": must be -ascii, -command, -decreasing, -dictionary, -increasing, -index, -integer, or -real}}
21
test cmdIL-1.3 {Tcl_LsortObjCmd procedure, default options} {
22
    lsort {d e c b a \{ d35 d300}
23
} {a b c d d300 d35 e \{}
24
test cmdIL-1.4 {Tcl_LsortObjCmd procedure, -ascii option} {
25
    lsort -integer -ascii {d e c b a d35 d300}
26
} {a b c d d300 d35 e}
27
test cmdIL-1.5 {Tcl_LsortObjCmd procedure, -command option} {
28
    list [catch {lsort -command {1 3 2 5}} msg] $msg
29
} {1 {"-command" option must be followed by comparison command}}
30
test cmdIL-1.6 {Tcl_LsortObjCmd procedure, -command option} {
31
    proc cmp {a b} {
32
        expr {[string match x* $b] - [string match x* $a]}
33
    }
34
    lsort -command cmp {x1 abc x2 def x3 x4}
35
} {x1 x2 x3 x4 abc def}
36
test cmdIL-1.7 {Tcl_LsortObjCmd procedure, -decreasing option} {
37
    lsort -decreasing {d e c b a d35 d300}
38
} {e d35 d300 d c b a}
39
test cmdIL-1.8 {Tcl_LsortObjCmd procedure, -dictionary option} {
40
    lsort -dictionary {d e c b a d35 d300}
41
} {a b c d d35 d300 e}
42
test cmdIL-1.9 {Tcl_LsortObjCmd procedure, -dictionary option} {
43
    lsort -dictionary {1k 0k 10k}
44
} {0k 1k 10k}
45
test cmdIL-1.10 {Tcl_LsortObjCmd procedure, -increasing option} {
46
    lsort -decreasing -increasing {d e c b a d35 d300}
47
} {a b c d d300 d35 e}
48
test cmdIL-1.11 {Tcl_LsortObjCmd procedure, -index option} {
49
    list [catch {lsort -index {1 3 2 5}} msg] $msg
50
} {1 {"-index" option must be followed by list index}}
51
test cmdIL-1.12 {Tcl_LsortObjCmd procedure, -index option} {
52
    list [catch {lsort -index foo {1 3 2 5}} msg] $msg
53
} {1 {bad index "foo": must be integer or "end"}}
54
test cmdIL-1.13 {Tcl_LsortObjCmd procedure, -index option} {
55
    lsort -index end -integer {{2 25} {10 20 50 100} {3 16 42} 1}
56
} {1 {2 25} {3 16 42} {10 20 50 100}}
57
test cmdIL-1.14 {Tcl_LsortObjCmd procedure, -index option} {
58
    lsort -index 1 -integer {{1 25 100} {3 16 42} {10 20 50}}
59
} {{3 16 42} {10 20 50} {1 25 100}}
60
test cmdIL-1.15 {Tcl_LsortObjCmd procedure, -integer option} {
61
    lsort -integer {24 6 300 18}
62
} {6 18 24 300}
63
test cmdIL-1.16 {Tcl_LsortObjCmd procedure, -integer option} {
64
    list [catch {lsort -integer {1 3 2.4}} msg] $msg
65
} {1 {expected integer but got "2.4"}}
66
test cmdIL-1.17 {Tcl_LsortObjCmd procedure, -real option} {
67
    lsort -real {24.2 6e3 150e-1}
68
} {150e-1 24.2 6e3}
69
test cmdIL-1.18 {Tcl_LsortObjCmd procedure, bogus list} {
70
    list [catch {lsort "1 2 3 \{ 4"} msg] $msg
71
} {1 {unmatched open brace in list}}
72
test cmdIL-1.19 {Tcl_LsortObjCmd procedure, empty list} {
73
    lsort {}
74
} {}
75
 
76
# Can't think of any good tests for the MergeSort and MergeLists
77
# procedures, except a bunch of random lists to sort.
78
 
79
test cmdIL-2.1 {MergeSort and MergeLists procedures} {
80
    set result {}
81
    set r 1435753299
82
    proc rand {} {
83
        global r
84
        set r [expr (16807 * $r) % (0x7fffffff)]
85
    }
86
    for {set i 0} {$i < 150} {incr i} {
87
        set x {}
88
        for {set j 0} {$j < $i} {incr j} {
89
            lappend x [expr [rand] & 0xfff]
90
        }
91
        set y [lsort -integer $x]
92
        set old -1
93
        foreach el $y {
94
            if {$el < $old} {
95
                append result "list {$x} sorted to {$y}, element $el out of order\n"
96
                break
97
            }
98
            set old $el
99
        }
100
    }
101
    set result
102
} {}
103
 
104
test cmdIL-3.1 {SortCompare procedure, skip comparisons after error} {
105
    set x 0
106
    proc cmp {a b} {
107
        global x
108
        incr x
109
        error "error #$x"
110
    }
111
    list [catch {lsort -integer -command cmp {48 6 28 190 16 2 3 6 1}} msg] \
112
            $msg $x
113
} {1 {error #1} 1}
114
test cmdIL-3.2 {SortCompare procedure, -index option} {
115
    list [catch {lsort -integer -index 2 "\\\{ {30 40 50}"} msg] $msg
116
} {1 {unmatched open brace in list}}
117
test cmdIL-3.3 {SortCompare procedure, -index option} {
118
    list [catch {lsort -integer -index 2 {{20 10} {15 30 40}}} msg] $msg
119
} {1 {element 2 missing from sublist "20 10"}}
120
test cmdIL-3.4 {SortCompare procedure, -index option} {
121
    list [catch {lsort -integer -index 2 "{a b c} \\\{"} msg] $msg
122
} {1 {unmatched open brace in list}}
123
test cmdIL-3.5 {SortCompare procedure, -index option} {
124
    list [catch {lsort -integer -index 2 {{20 10 13} {15}}} msg] $msg
125
} {1 {element 2 missing from sublist "15"}}
126
test cmdIL-3.6 {SortCompare procedure, -index option} {
127
    lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}}
128
} {{3 25 20} {2 5 25} {1 15 30}}
129
test cmdIL-3.7 {SortCompare procedure, -ascii option} {
130
    lsort -ascii {d e c b a d35 d300 100 20}
131
} {100 20 a b c d d300 d35 e}
132
test cmdIL-3.8 {SortCompare procedure, -dictionary option} {
133
    lsort -dictionary {d e c b a d35 d300 100 20}
134
} {20 100 a b c d d35 d300 e}
135
test cmdIL-3.9 {SortCompare procedure, -integer option} {
136
    list [catch {lsort -integer {x 3}} msg] $msg
137
} {1 {expected integer but got "x"}}
138
test cmdIL-3.10 {SortCompare procedure, -integer option} {
139
    list [catch {lsort -integer {3 q}} msg] $msg
140
} {1 {expected integer but got "q"}}
141
test cmdIL-3.11 {SortCompare procedure, -integer option} {
142
    lsort -integer {35 21 0x20 30 023 100 8}
143
} {8 023 21 30 0x20 35 100}
144
test cmdIL-3.12 {SortCompare procedure, -real option} {
145
    list [catch {lsort -real {6...4 3}} msg] $msg
146
} {1 {expected floating-point number but got "6...4"}}
147
test cmdIL-3.13 {SortCompare procedure, -real option} {
148
    list [catch {lsort -real {3 1x7}} msg] $msg
149
} {1 {expected floating-point number but got "1x7"}}
150
test cmdIL-3.14 {SortCompare procedure, -real option} {
151
    lsort -real {24 2.5e01 16.7 85e-1 10.004}
152
} {85e-1 10.004 16.7 24 2.5e01}
153
test cmdIL-3.15 {SortCompare procedure, -command option} {
154
    proc cmp {a b} {
155
        error "comparison error"
156
    }
157
    list [catch {lsort -command cmp {48 6}} msg] $msg $errorInfo
158
} {1 {comparison error} {comparison error
159
    while executing
160
"error "comparison error""
161
    (procedure "cmp" line 2)
162
    invoked from within
163
"cmp 48 6"
164
    (-compare command)
165
    invoked from within
166
"lsort -command cmp {48 6}"}}
167
test cmdIL-3.16 {SortCompare procedure, -command option, long command} {
168
    proc cmp {dummy a b} {
169
        string compare $a $b
170
    }
171
    lsort -command {cmp {this argument is very very long in order to make the dstring overflow its statically allocated space}} {{this first element is also long in order to help expand the dstring} {the second element, last but not least, is quite long also, in order to make absolutely sure that space is allocated dynamically for the dstring}}
172
} {{the second element, last but not least, is quite long also, in order to make absolutely sure that space is allocated dynamically for the dstring} {this first element is also long in order to help expand the dstring}}
173
test cmdIL-3.17 {SortCompare procedure, -command option, non-integer result} {
174
    proc cmp {a b} {
175
        return foow
176
    }
177
    list [catch {lsort -command cmp {48 6}} msg] $msg
178
} {1 {-compare command returned non-numeric result}}
179
test cmdIL-3.18 {SortCompare procedure, -command option} {
180
    proc cmp {a b} {
181
        expr $b - $a
182
    }
183
    lsort -command cmp {48 6 18 22 21 35 36}
184
} {48 36 35 22 21 18 6}
185
test cmdIL-3.19 {SortCompare procedure, -decreasing option} {
186
    lsort -decreasing -integer {35 21 0x20 30 023 100 8}
187
} {100 35 0x20 30 21 023 8}
188
 
189
test cmdIL-4.1 {DictionaryCompare procedure, numerics, leading zeros} {
190
    lsort -dictionary {a003b a03b}
191
} {a03b a003b}
192
test cmdIL-4.2 {DictionaryCompare procedure, numerics, leading zeros} {
193
    lsort -dictionary {a3b a03b}
194
} {a3b a03b}
195
test cmdIL-4.3 {DictionaryCompare procedure, numerics, leading zeros} {
196
    lsort -dictionary {a3b A03b}
197
} {A03b a3b}
198
test cmdIL-4.4 {DictionaryCompare procedure, numerics, leading zeros} {
199
    lsort -dictionary {a3b a03B}
200
} {a3b a03B}
201
test cmdIL-4.5 {DictionaryCompare procedure, numerics, leading zeros} {
202
    lsort -dictionary {00000 000}
203
} {000 00000}
204
test cmdIL-4.6 {DictionaryCompare procedure, numerics, different lengths} {
205
    lsort -dictionary {a321b a03210b}
206
} {a321b a03210b}
207
test cmdIL-4.7 {DictionaryCompare procedure, numerics, different lengths} {
208
    lsort -dictionary {a03210b a321b}
209
} {a321b a03210b}
210
test cmdIL-4.8 {DictionaryCompare procedure, numerics} {
211
    lsort -dictionary {48 6a 18b 22a 21aa 35 36}
212
} {6a 18b 21aa 22a 35 36 48}
213
test cmdIL-4.9 {DictionaryCompare procedure, numerics} {
214
    lsort -dictionary {a123x a123b}
215
} {a123b a123x}
216
test cmdIL-4.10 {DictionaryCompare procedure, numerics} {
217
    lsort -dictionary {a123b a123x}
218
} {a123b a123x}
219
test cmdIL-4.11 {DictionaryCompare procedure, numerics} {
220
    lsort -dictionary {a1b aab}
221
} {a1b aab}
222
test cmdIL-4.12 {DictionaryCompare procedure, numerics} {
223
    lsort -dictionary {a1b a!b}
224
} {a!b a1b}
225
test cmdIL-4.13 {DictionaryCompare procedure, numerics} {
226
    lsort -dictionary {a1b2c a1b1c}
227
} {a1b1c a1b2c}
228
test cmdIL-4.14 {DictionaryCompare procedure, numerics} {
229
    lsort -dictionary {a1b2c a1b3c}
230
} {a1b2c a1b3c}
231
test cmdIL-4.15 {DictionaryCompare procedure, long numbers} {
232
    lsort -dictionary {a7654884321988762b a7654884321988761b}
233
} {a7654884321988761b a7654884321988762b}
234
test cmdIL-4.16 {DictionaryCompare procedure, long numbers} {
235
    lsort -dictionary {a8765488432198876b a7654884321988761b}
236
} {a7654884321988761b a8765488432198876b}
237
test cmdIL-4.17 {DictionaryCompare procedure, case} {
238
    lsort -dictionary {aBCd abcc}
239
} {abcc aBCd}
240
test cmdIL-4.18 {DictionaryCompare procedure, case} {
241
    lsort -dictionary {aBCd abce}
242
} {aBCd abce}
243
test cmdIL-4.19 {DictionaryCompare procedure, case} {
244
    lsort -dictionary {abcd ABcc}
245
} {ABcc abcd}
246
test cmdIL-4.20 {DictionaryCompare procedure, case} {
247
    lsort -dictionary {abcd ABce}
248
} {abcd ABce}
249
test cmdIL-4.21 {DictionaryCompare procedure, case} {
250
    lsort -dictionary {abCD ABcd}
251
} {ABcd abCD}
252
test cmdIL-4.22 {DictionaryCompare procedure, case} {
253
    lsort -dictionary {ABcd aBCd}
254
} {ABcd aBCd}
255
test cmdIL-4.23 {DictionaryCompare procedure, case} {
256
    lsort -dictionary {ABcd AbCd}
257
} {ABcd AbCd}
258
test cmdIL-4.24 {DefaultCompare procedure, signed characters} {
259
    set l [lsort [list "abc\200" "abc"]]
260
    set viewlist {}
261
    foreach s $l {
262
        set viewelem ""
263
        set len [string length $s]
264
        for {set i 0} {$i < $len} {incr i} {
265
            set c [string index $s $i]
266
            scan $c %c d
267
            if {$d > 0 && $d < 128} {
268
                append viewelem $c
269
            } else {
270
                append viewelem "\\[format %03o $d]"
271
            }
272
        }
273
        lappend viewlist $viewelem
274
    }
275
    set viewlist
276
} [list "abc" "abc\\200"]
277
test cmdIL-4.25 {DictionaryCompare procedure, signed characters} {
278
    set l [lsort -dictionary [list "abc\200" "abc"]]
279
    set viewlist {}
280
    foreach s $l {
281
        set viewelem ""
282
        set len [string length $s]
283
        for {set i 0} {$i < $len} {incr i} {
284
            set c [string index $s $i]
285
            scan $c %c d
286
            if {$d > 0 && $d < 128} {
287
                append viewelem $c
288
            } else {
289
                append viewelem "\\[format %03o $d]"
290
            }
291
        }
292
        lappend viewlist $viewelem
293
    }
294
    set viewlist
295
} [list "abc" "abc\\200"]

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.