diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/expr.test | 93 | ||||
-rw-r--r-- | tests/info.test | 4 |
2 files changed, 94 insertions, 3 deletions
diff --git a/tests/expr.test b/tests/expr.test index 7064f17..51b66bd 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: expr.test,v 1.65 2006/11/05 03:33:57 dgp Exp $ +# RCS: @(#) $Id: expr.test,v 1.66 2006/12/01 20:00:00 kennykb Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2.1 @@ -6556,6 +6556,97 @@ test expr-46.19 {round() handling of long/bignum boundary} { expr {round(double(0x7fffffffffffffff))} } 9223372036854775808 +test expr-47.1 {isqrt() - arg count} { + list [catch {expr {isqrt(1,2)}} result] $result +} {1 {too many arguments for math function "isqrt"}} + +test expr-47.2 {isqrt() - non-number} { + list [catch {expr {isqrt({rubbish})}} result] $result +} {1 {expected number but got "rubbish"}} + +test expr-47.3 {isqrt() - NaN} ieeeFloatingPoint { + list [catch {expr {isqrt(NaN)}} result] $result +} {1 {floating point value is Not a Number}} + +test expr-47.4 {isqrt() of negative floating point number} { + list [catch {expr {isqrt(-1.0)}} result] $result +} {1 {square root of negative argument}} + +test expr-47.5 {isqrt() of floating point zero} { + expr isqrt(0.0) +} 0 + +test expr-47.6 {isqrt() of exact floating point numbers} { + set trouble {} + for {set i 0} {$i < 16} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {pow(2., (2 * $i))}] + if {isqrt($arg-1) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} + +test expr-47.7 {isqrt() of exact floating point numbers} ieeeFloatingPoint { + set trouble {} + for {set i 17} {$i < 27} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {pow(2., (2 * $i))}] + if {isqrt($arg-1.0) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1.0) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} + +test expr-47.8 {isqrt of inexact floating point number} ieeeFloatingPoint { + expr isqrt(2[string repeat 0 34]) +} 141421356237309504 + +test expr-47.9 {isqrt of negative int} { + list [catch {expr isqrt(-1)} result] $result +} {1 {square root of negative argument}} + +test expr-47.10 {isqrt of negative bignum} { + list [catch {expr isqrt(-1[string repeat 0 1000])} result] $result +} {1 {square root of negative argument}} + +test expr-47.11 {isqrt of zero} { + expr {isqrt(0)} +} 0 + +test expr-47.12 {isqrt of various sizes of integer} { + for {set i 0} {$i < 3000} {incr i} { + set root [expr {1 << $i}] + set rm1 [expr {$root - 1}] + set arg [expr {1 << (2 * $i)}] + if {isqrt($arg-1) != $rm1} { + append trouble "i = " $i ": isqrt( " $arg "-1) != " $rm1 "\n" + } + if {isqrt($arg) != $root} { + append trouble "i = " $i ": isqrt( " $arg ") != " $root "\n" + } + if {isqrt($arg+1) != $root} { + append trouble "i = " $i ": isqrt( " $arg "+1) != " $root "\n" + } + } + set trouble +} {} # cleanup if {[info exists a]} { diff --git a/tests/info.test b/tests/info.test index 7b7b867..82c942b 100644 --- a/tests/info.test +++ b/tests/info.test @@ -13,7 +13,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: info.test,v 1.40 2006/11/28 22:20:29 andreas_kupries Exp $ +# RCS: @(#) $Id: info.test,v 1.41 2006/12/01 20:00:00 kennykb Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -644,7 +644,7 @@ test info-19.6 {info vars: Bug 1072654} -setup { namespace delete x } -result {} -set functions {abs acos asin atan atan2 bool ceil cos cosh double entier exp floor fmod hypot int log log10 max min pow rand round sin sinh sqrt srand tan tanh wide} +set functions {abs acos asin atan atan2 bool ceil cos cosh double entier exp floor fmod hypot int isqrt log log10 max min pow rand round sin sinh sqrt srand tan tanh wide} # Check whether the extra testing functions are defined... if {!([catch {expr T1()} msg] && ($msg eq {invalid command name "tcl::mathfunc::T1"}))} { set functions "T1 T2 T3 $functions" ;# A lazy way of prepending! |