home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / loop.test < prev    next >
Encoding:
Text File  |  1994-01-23  |  2.7 KB  |  144 lines

  1. #
  2. # loop.test
  3. #
  4. # Tests for the loop command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: loop.test,v 3.0 1993/11/19 06:57:53 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. Test loop-1.1 {loop tests} {
  22.     set a {}
  23.     set i 1
  24.     loop i 1 6 {
  25.         set a [concat $a $i]
  26.     }
  27.     set a
  28. } 0 {1 2 3 4 5}
  29.  
  30. Test loop-1.2 {loop tests} {
  31.     set a {}
  32.     loop i 1 6 {
  33.         if {$i == 4} {
  34.             continue}
  35.         set a [concat $a $i]
  36.     }
  37.     set a
  38. } 0 {1 2 3 5}
  39.  
  40. Test loop-1.3 {loop tests} {
  41.     set a {}
  42.     loop i 1 6 {
  43.         if $i==4 break
  44.         set a [concat $a $i]
  45.     }
  46.     set a
  47. } 0 {1 2 3}
  48.  
  49. Test loop-1.4 {loop tests} {
  50.     loop 1 2 3
  51. } 1 {wrong # args: loop var first limit ?incr? command}
  52.  
  53. Test loop-1.5 {loop tests} {
  54.     loop 1 2 3 4 5 6
  55. } 1 {wrong # args: loop var first limit ?incr? command}
  56.  
  57. Test loop-1.6 {loop tests} {
  58.     set a {}
  59.     loop i 1 6 {
  60.         set a [concat $a $i]
  61.         set i 100
  62.     }
  63.     set a
  64. } 0 {1 2 3 4 5}
  65.  
  66. Test loop-1.7 {loop tests} {
  67.     set a {}
  68.     loop i 1 6 2 {
  69.         set a [concat $a $i]
  70.     }
  71.     set a
  72. } 0 {1 3 5}
  73.  
  74. Test loop-1.8 {loop tests} {
  75.     set a {}
  76.     set i 1
  77.     loop i 6 1 -1 {
  78.         set a [concat $a $i]
  79.     }
  80.     set a
  81. } 0 {6 5 4 3 2}
  82.  
  83. Test loop-1.9 {loop tests} {
  84.     set a {}
  85.     loop i 6 1 -1 {
  86.         if $i==4 {
  87.             continue}
  88.         set a [concat $a $i]
  89.     }
  90.     set a
  91. } 0 {6 5 3 2}
  92.  
  93. Test loop-1.10 {loop tests} {
  94.     set a {}
  95.     loop i 6 1 -1 {
  96.         if {$i == 4} {
  97.             break}
  98.         set a [concat $a $i]
  99.     }
  100.     set a
  101. } 0 {6 5}
  102.  
  103. Test loop-1.11 {loop tests} {
  104.     set j 0
  105.     loop i 65536 65556 {
  106.         incr j
  107.     }
  108.     set j
  109. } 0 20
  110.  
  111. Test loop-1.12 {loop tests} {
  112.     set j 0
  113.     loop i 65556 65536 -1 {
  114.         incr j 1
  115.     }
  116.     set j
  117. } 0 20
  118.  
  119. Test loop-1.13 {loop tests} {
  120.     set j 0
  121.     loop i 0 655360 65536 {
  122.         incr j 1
  123.     }
  124.     set j
  125. } 0 10
  126.  
  127. Test loop-1.13 {loop tests} {
  128.     set j 0
  129.     loop i 655360 0 -65536 {
  130.         incr j 1
  131.     }
  132.     set j
  133. } 0 10
  134.  
  135. Test loop-1.9 {loop tests} {
  136.     set a {}
  137.     set i 1
  138.     loop i 3*2 0+1 10-11 {
  139.         set a [concat $a $i]
  140.     }
  141.     set a
  142. } 0 {6 5 4 3 2}
  143.  
  144.