From 2da690df065ecf6648f8bcd07048efca00b78726 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 1 Sep 2022 14:09:11 +0000 Subject: Add empty "range.test": GIT doesn't handling file renames well .... --- tests/range.test | 343 ------------------------------------------------------- 1 file changed, 343 deletions(-) diff --git a/tests/range.test b/tests/range.test index d1e96ad..e69de29 100644 --- a/tests/range.test +++ b/tests/range.test @@ -1,343 +0,0 @@ -# Commands covered: range -# -# This file contains a collection of tests for one or more of the Tcl -# built-in commands. Sourcing this file into Tcl runs the tests and -# generates output for errors. No output means no errors were found. -# -# Copyright © 2003 Simon Geard. -# -# See the file "license.terms" for information on usage and redistribution -# of this file, and for a DISCLAIMER OF ALL WARRANTIES. - -if {"::tcltest" ni [namespace children]} { - package require tcltest 2.5 - namespace import -force ::tcltest::* -} - -testConstraint arithSeriesDouble 0 -testConstraint arithSeriesShimmer 1 -testConstraint arithSeriesShimmerOk 0 - -## Arg errors -test range-1.1 {error cases} -body { - range -} \ - -returnCodes 1 \ - -result {wrong # args: should be "range n ??op? n ??by? n??"} - - -test range-1.2 {step magnitude} { - range 10 .. 1 by -2 ;# or this could be an error - or not -} {10 8 6 4 2} - -test range-1.3 {synergy between int and double} { - set rl [range 25. to 5. by -5] - set il [range 25 to 5 by -5] - lmap r $rl i $il { if {$r ne "" && $i ne ""} {expr {int($r) == $i}} else {list $r $i} } -} {1 1 1 1 1} - -test range-1.4 {integer decreasing} { - range 10 .. 1 -} {10 9 8 7 6 5 4 3 2 1} - -test range-1.5 {integer increasing} { - range 1 .. 10 -} {1 2 3 4 5 6 7 8 9 10} - -test range-1.6 {integer decreasing with step} { - range 10 .. 1 by -2 -} {10 8 6 4 2} - -test range-1.7 {real increasing range} arithSeriesDouble { - range 5.0 to 15. -} {5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0} - -test range-1.8 {real increasing range with step} arithSeriesDouble { - range 5.0 to 25. by 5 -} {5.0 10.0 15.0 20.0 25.0} - -test range-1.9 {real decreasing with step} arithSeriesDouble { - range 25. to 5. by -5 -} {25.0 20.0 15.0 10.0 5.0} - -# note, 10 cannot be in such a list, but allowed -test range-1.10 {integer range with step} { - range 1 to 10 by 2 -} {1 3 5 7 9} - -test range-1.11 {error case: increasing wrong step direction} { - range 1 to 10 by -2 -} {} - -test range-1.12 {decreasing range with step} arithSeriesDouble { - range 25. to -25. by -5 -} { 25.0 20.0 15.0 10.0 5.0 0.0 -5.0 -10.0 -15.0 -20.0 -25.0} - -test range-1.13 {count operation} { - -body { - range 5 count 5 - } - -result {5 6 7 8 9} -} - -test range-1.14 {count with step} { - -body { - range 5 count 5 by 2 - } - -result {5 7 9 11 13} -} - -test range-1.15 {count with decreasing step} { - -body { - range 5 count 5 by -2 - } - -result {5 3 1 -1 -3} -} - -test range-1.16 {large numbers} { - -body { - range [expr {int(1e6)}] [expr {int(2e6)}] [expr {int(1e5)}] - } - -result {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000} -} - -test range-1.17 {too many arguments} -body { - range 12 to 24 by 2 with feeling -} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"} - -test range-1.18 {too many arguments extra valid keyword} -body { - range 12 to 24 by 2 count -} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"} - -test range-1.19 {too many arguments extra numeric value} -body { - range 12 to 24 by 2 7 -} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"} - -# -# Short-hand use cases -# -test range-2.2 {step magnitude} { - range 10 1 2 ;# this is an empty case since step has wrong sign -} {} - -test range-2.3 {step wrong sign} arithSeriesDouble { - range 25. 5. 5 ;# ditto - empty list -} {} - -test range-2.4 {integer decreasing} { - range 10 1 -} {10 9 8 7 6 5 4 3 2 1} - -test range-2.5 {integer increasing} { - range 1 10 -} {1 2 3 4 5 6 7 8 9 10} - -test range-2.6 {integer decreasing with step} { - range 10 1 by -2 -} {10 8 6 4 2} - -test range-2.7 {real increasing range} arithSeriesDouble { - range 5.0 15. -} {5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0} - - -test range-2.8 {real increasing range with step} arithSeriesDouble { - range 5.0 25. 5 -} {5.0 10.0 15.0 20.0 25.0} - - -test range-2.9 {real decreasing with step} arithSeriesDouble { - range 25. 5. -5 -} {25.0 20.0 15.0 10.0 5.0} - -test range-2.10 {integer range with step} { - range 1 10 2 -} {1 3 5 7 9} - -test range-2.11 {error case: increasing wrong step direction} { - range 1 10 -2 -} {} - -test range-2.12 {decreasing range with step} arithSeriesDouble { - range 25. -25. -5 -} { 25.0 20.0 15.0 10.0 5.0 0.0 -5.0 -10.0 -15.0 -20.0 -25.0} - -test range-2.13 {count only operation} { - range 5 -} {0 1 2 3 4} - -test range-2.14 {count with step} { - range 5 count 5 2 -} {5 7 9 11 13} - -test range-2.15 {count with decreasing step} { - range 5 count 5 -2 -} {5 3 1 -1 -3} - -test range-2.16 {large numbers} { - range 1e6 2e6 1e5 -} {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000} - -test range-2.17 {large numbers} arithSeriesDouble { - range 1e6 2e6 1e5 -} {1000000.0 1100000.0 1200000.0 1300000.0 1400000.0 1500000.0 1600000.0 1700000.0 1800000.0 1900000.0 2000000.0} - - -test range-3.1 {experiement} { - set ans {} - foreach factor [range 2.0 10.0] { - set start 1 - set end 10 - for {set step 1} {$step < 1e8} {} { - set l [range $start to $end by $step] - if {[llength $l] != 10} { - lappend ans $factor $step [llength $l] $l - } - set step [expr {$step * $factor}] - set end [expr {$end * $factor}] - } - } - if {$ans eq {}} { - set ans OK - } - set ans -} {OK} - -test range-3.2 {error case} -body { - range foo -} -returnCodes 1 -result {bad operation "foo": must be .., to, count, or by} - -test range-3.3 {error case} -body { - range 10 foo -} -returnCodes 1 -result {bad operation "foo": must be .., to, count, or by} - -test range-3.4 {error case} -body { - range 25 or 6 -} -returnCodes 1 -result {bad operation "or": must be .., to, count, or by} - -test range-3.5 {simple count and step arguments} { - range 25 by 6 -} {0 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 126 132 138 144 150} - -test range-3.6 {error case} -body { - range 1 7 or 3 -} -returnCodes 1 -result {bad operation "or": must be .., to, count, or by} - -test range-3.7 {lmap range} { - lmap x [range 5] { expr {$x * $x} } -} {0 1 4 9 16} - -test range-3.8 {lrange range} { - set r [lrange [range 1 100] 10 20] - lindex [tcl::unsupported::representation $r] 3 -} {arithseries} - -test range-3.9 {lassign range} arithSeriesShimmer { - set r [range 15] - set r2 [lassign $r a b] - list [lindex [tcl::unsupported::representation $r] 3] $a $b \ - [lindex [tcl::unsupported::representation $r2] 3] -} {arithseries 0 1 arithseries} - -test range-3.10 {lsearch range must shimmer?} arithSeriesShimmer { - set r [range 15 0] - set a [lsearch $r 9] - list [lindex [tcl::unsupported::representation $r] 3] $a -} {list 6} - -test range-3.11 {lreverse range} { - set r [range 15 0] - set a [lreverse $r] - join [list \ - [lindex [tcl::unsupported::representation $r] 3] \ - $r \ - [lindex [tcl::unsupported::representation $a] 3] \ - $a] \n -} {arithseries -15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 -arithseries -0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} - -test range-3.12 {in operator} { - set r [range 9] - set i [expr {7 in $r}] - set j [expr {10 ni $r}] - set k [expr {-1 in $r}] - set l [expr {4 ni $r}] - list $i $j $k $l [lindex [tcl::unsupported::representation $r] 3] -} {1 1 0 0 arithseries} - -test range-3.13 {lmap range shimmer} arithSeriesShimmer { - set r [range 15] - set rep-before [lindex [tcl::unsupported::representation $r] 3] - set m [lmap i $r { expr {$i * 7} }] - set rep-after [lindex [tcl::unsupported::representation $r] 3] - set rep-m [lindex [tcl::unsupported::representation $m] 3] - list $r ${rep-before} ${rep-after} ${rep-m} $m -} {{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} arithseries arithseries list {0 7 14 21 28 35 42 49 56 63 70 77 84 91 98}} - -test range-3.14 {array for shimmer} arithSeriesShimmerOk { - array set testarray {a Test for This great Function} - set vars [range 2] - set vars-rep [lindex [tcl::unsupported::representation $vars] 3] - array for $vars testarray { - lappend keys $0 - lappend vals $1 - } - # Since hash order is not guaranteed, have to validate content ignoring order - set valk [lmap k $keys {expr {$k in {a for great}}}] - set valv [lmap v $vals {expr {$v in {Test This Function}}}] - set vars-after [lindex [tcl::unsupported::representation $vars] 3] - list ${vars-rep} $valk $valv ${vars-after} -} {arithseries {1 1 1} {1 1 1} arithseries} - -test range-3.15 {join for shimmer} arithSeriesShimmerOk { - set r [range 3] - set rep-before [lindex [tcl::unsupported::representation $r] 3] - set str [join $r :] - set rep-after [lindex [tcl::unsupported::representation $r] 3] - list ${rep-before} $str ${rep-after} -} {arithseries 0:1:2 arithseries} - -test range-3.16 {error case} -body { - range 16 to -} -returnCodes 1 -result {missing "to" value.} - -test range-3.17 {error case} -body { - range 17 to 13 by -} -returnCodes 1 -result {missing "by" value.} - -test range-3.18 {error case} -body { - range 18 count -} -returnCodes 1 -result {missing "count" value.} - - -# Test lmap -# Test "in" expression operator -# Test llength -# Test lindex -# Test lrange (lrange of a [range] list produces another [range] list) -# Test start,end,step expressions -# Test lreverse -# Test lsearch -# Test array for -# Test join for shimmer. - -test range-4.1 {end expressions} { - set start 7 - range $start $start+11 -} {7 8 9 10 11 12 13 14 15 16 17 18} - -test range-4.2 {start expressions} { - set base [clock seconds] - set tl [range $base-60 $base 10] - lmap t $tl {expr {$t - $base + 60}} -} {0 10 20 30 40 50 60} - -# cleanup -::tcltest::cleanupTests -return - -# Local Variables: -# mode: tcl -# End: -- cgit v0.12