summaryrefslogtreecommitdiffstats
path: root/tests/lseq.test
diff options
context:
space:
mode:
authorgriffin <briang42@easystreet.net>2022-08-28 00:10:13 (GMT)
committergriffin <briang42@easystreet.net>2022-08-28 00:10:13 (GMT)
commit31c68fa4e741269ba96b1411eca08a67001079f2 (patch)
treeec21eaf79c1107e1491b3bc407adff6be31311b1 /tests/lseq.test
parentf9e3b4dd740c0d808fef53f9eba4b44e67734c34 (diff)
downloadtcl-31c68fa4e741269ba96b1411eca08a67001079f2.zip
tcl-31c68fa4e741269ba96b1411eca08a67001079f2.tar.gz
tcl-31c68fa4e741269ba96b1411eca08a67001079f2.tar.bz2
Move all ArithSeries code to it's own file. Sync other changes wil TIP-629.
Diffstat (limited to 'tests/lseq.test')
-rw-r--r--tests/lseq.test113
1 files changed, 96 insertions, 17 deletions
diff --git a/tests/lseq.test b/tests/lseq.test
index 0919813..4c837ba 100644
--- a/tests/lseq.test
+++ b/tests/lseq.test
@@ -14,7 +14,7 @@ if {"::tcltest" ni [namespace children]} {
namespace import -force ::tcltest::*
}
-testConstraint arithSeriesDouble 0
+testConstraint arithSeriesDouble 1
testConstraint arithSeriesShimmer 1
testConstraint arithSeriesShimmerOk 0
@@ -71,23 +71,35 @@ test lseq-1.11 {error case: increasing wrong step direction} {
test lseq-1.12 {decreasing lseq with step} arithSeriesDouble {
lseq 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}
+} {25.0 20.0 15.0 10.0 5.0 0.0 -5.0 -10.0 -15.0 -20.0 -25.0}
-test lseq-1.13 {count operation} -body {
- lseq 5 count 5
-} -result {5 6 7 8 9}
+test lseq-1.13 {count operation} {
+ -body {
+ lseq 5 count 5
+ }
+ -result {5 6 7 8 9}
+}
-test lseq-1.14 {count with step} -body {
- lseq 5 count 5 by 2
-} -result {5 7 9 11 13}
+test lseq-1.14 {count with step} {
+ -body {
+ lseq 5 count 5 by 2
+ }
+ -result {5 7 9 11 13}
+}
-test lseq-1.15 {count with decreasing step} -body {
- lseq 5 count 5 by -2
-} -result {5 3 1 -1 -3}
+test lseq-1.15 {count with decreasing step} {
+ -body {
+ lseq 5 count 5 by -2
+ }
+ -result {5 3 1 -1 -3}
+}
-test lseq-1.16 {large numbers} -body {
- lseq [expr {int(1e6)}] [expr {int(2e6)}] [expr {int(1e5)}]
-} -result {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000}
+test lseq-1.16 {large numbers} {
+ -body {
+ lseq [expr {int(1e6)}] [expr {int(2e6)}] [expr {int(1e5)}]
+ }
+ -result {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000}
+}
test lseq-1.17 {too many arguments} -body {
lseq 12 to 24 by 2 with feeling
@@ -160,7 +172,7 @@ test lseq-2.11 {error case: increasing wrong step direction} {
test lseq-2.12 {decreasing lseq with step} arithSeriesDouble {
lseq 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}
+} {25.0 20.0 15.0 10.0 5.0 0.0 -5.0 -10.0 -15.0 -20.0 -25.0}
test lseq-2.13 {count only operation} {
lseq 5
@@ -176,7 +188,7 @@ test lseq-2.15 {count with decreasing step} {
test lseq-2.16 {large numbers} {
lseq 1e6 2e6 1e5
-} {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000}
+} {1000000.0 1100000.0 1200000.0 1300000.0 1400000.0 1500000.0 1600000.0 1700000.0 1800000.0 1900000.0 2000000.0}
test lseq-2.17 {large numbers} arithSeriesDouble {
lseq 1e6 2e6 1e5
@@ -382,6 +394,23 @@ test lseq-3.29 {edge case: negative count} {
lseq -15
} {}
+test lseq-3.30 {lreverse with double values} arithSeriesDouble {
+ set r [lseq 3.5 18.5 1.5]
+ set a [lreverse $r]
+ join [list \
+ [lindex [tcl::unsupported::representation $r] 3] \
+ $r \
+ [lindex [tcl::unsupported::representation $a] 3] \
+ $a] \n
+} {arithseries
+3.5 5.0 6.5 8.0 9.5 11.0 12.5 14.0 15.5 17.0 18.5
+arithseries
+18.5 17.0 15.5 14.0 12.5 11.0 9.5 8.0 6.5 5.0 3.5}
+
+test lseq-3.31 {lreverse inplace with doubles} arithSeriesDouble {
+ lreverse [lseq 1.1 29.9 0.3]
+} {29.9 29.599999999999998 29.299999999999997 29.0 28.7 28.4 28.099999999999998 27.799999999999997 27.5 27.2 26.9 26.599999999999998 26.299999999999997 26.0 25.7 25.4 25.099999999999998 24.799999999999997 24.5 24.2 23.9 23.599999999999998 23.299999999999997 23.0 22.7 22.4 22.099999999999998 21.799999999999997 21.5 21.2 20.9 20.6 20.299999999999997 20.0 19.7 19.4 19.1 18.799999999999997 18.5 18.2 17.9 17.6 17.299999999999997 17.0 16.7 16.4 16.1 15.799999999999999 15.5 15.2 14.899999999999999 14.6 14.299999999999999 14.0 13.7 13.399999999999999 13.099999999999998 12.8 12.5 12.2 11.899999999999999 11.599999999999998 11.3 11.0 10.7 10.399999999999999 10.099999999999998 9.8 9.5 9.2 8.899999999999999 8.599999999999998 8.3 8.0 7.699999999999999 7.399999999999999 7.099999999999998 6.800000000000001 6.5 6.199999999999999 5.899999999999999 5.599999999999998 5.300000000000001 5.0 4.699999999999999 4.399999999999999 4.099999999999998 3.8000000000000007 3.5 3.1999999999999993 2.8999999999999986 2.599999999999998 2.3000000000000007 2.0 1.6999999999999993 1.3999999999999986 1.1000000000000014}
+
test lseq-4.1 {end expressions} {
set start 7
lseq $start $start+11
@@ -393,11 +422,61 @@ test lseq-4.2 {start expressions} {
lmap t $tl {expr {$t - $base + 60}}
} {0 10 20 30 40 50 60}
+## lseq 1 to 10 by -2
+## # -> lseq: invalid step = -2 with a = 1 and b = 10
+
+test lseq-4.3 {TIP examples} {
+ set examples {# Examples from TIP-629
+ # --- Begin ---
+ lseq 10 .. 1
+ # -> 10 9 8 7 6 5 4 3 2 1
+ lseq 1 .. 10
+ # -> 1 2 3 4 5 6 7 8 9 10
+ lseq 10 .. 1 by 2
+ # ->
+ lseq 10 .. 1 by -2
+ # -> 10 8 6 4 2
+ lseq 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
+ lseq 5.0 to 25. by 5
+ # -> 5.0 10.0 15.0 20.0 25.0
+ lseq 25. to 5. by 5
+ # ->
+ lseq 25. to 5. by -5
+ # -> 25.0 20.0 15.0 10.0 5.0
+ lseq 1 to 10 by 2
+ # -> 1 3 5 7 9
+ lseq 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
+ lseq 5 5
+ # -> 5
+ lseq 5 5 2
+ # -> 5
+ lseq 5 5 -2
+ # -> 5
+ }
+
+ foreach {cmd expect} [split $examples \n] {
+ if {[string trim $cmd] ne ""} {
+ set cmd [string trimleft $cmd]
+ if {[string match {\#*} $cmd]} continue
+ set status [catch $cmd ans]
+ lappend res $ans
+ if {[regexp {\# -> (.*)$} $expect -> expected]} {
+ if {$expected ne $ans} {
+ lappend res [list Mismatch: $cmd -> $ans ne $expected]
+ }
+ }
+ }
+ }
+ set res
+} {{10 9 8 7 6 5 4 3 2 1} {1 2 3 4 5 6 7 8 9 10} {} {10 8 6 4 2} {5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0} {5.0 10.0 15.0 20.0 25.0} {} {25.0 20.0 15.0 10.0 5.0} {1 3 5 7 9} {25.0 20.0 15.0 10.0 5.0 0.0 -5.0 -10.0 -15.0 -20.0 -25.0} 5 5 5}
+
+
# cleanup
::tcltest::cleanupTests
return
-#
# Local Variables:
# mode: tcl
# End: