home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / cmdIL.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  10.0 KB  |  251 lines  |  [TEXT/ALFA]

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