1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
# -*- tcl -*-
# Tests for special (Bessel) functions in math library -*- tcl -*-
#
# This file contains a collection of tests for one or more of the Tcllib
# procedures. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# $Id: bessel.test,v 1.10 2005/09/28 04:51:22 andreas_kupries Exp $
#
# Copyright (c) 2004 by Arjen Markus
# All rights reserved.
#
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2.1
namespace import ::tcltest::*
} else {
# Ensure that 2.1 or higher present.
if {![package vsatisfies [package present tcltest] 2.1]} {
puts " Aborting tests for bessel in math::special."
puts " Requiring tcltest 2.1, have [package present tcltest]"
return
}
}
source [file join [file dirname [info script]] math.tcl]
source [file join [file dirname [info script]] special.tcl]
source [file join [file dirname [info script]] bessel.tcl]
package require math
#
# As the values were given with four digits, an absolute
# error is most appropriate
#
proc matchNumbers {expected actual} {
set match 1
foreach a $actual e $expected {
if {abs($a-$e) > 0.1e-4} {
set match 0
break
}
}
return $match
}
customMatch numbers matchNumbers
test "Bessel-1.0" "Values of the zeroth-order Bessel function" \
-match numbers -body {
set result {}
foreach x {0.0 1.0 2.0 5.0 7.0 10.0 11.0 14.0} {
lappend result [::math::special::J0 $x]
}
set result
} -result {1.0 0.765198 0.223891 -0.177597 0.300079 -0.245936 -0.171190 0.171073}
test "Bessel-1.1" "Values of the first-order Bessel function" \
-match numbers -body {
set result {}
foreach x {0.0 1.0 2.0 5.0 7.0 10.0 11.0 14.0} {
lappend result [::math::special::J1 $x]
}
set result
} -result {0.0 0.440050 0.576725 -0.327579 -0.004683 0.043473 -0.176785 0.133375}
#
# No tests for J1/2 yet
#
#
# No tests for I_n yet
#
# End of test cases
tcltest::cleanupTests
|