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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
# -*- tcl -*-
# Tests for special 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: special.test,v 1.13 2007/08/21 17:33:00 andreas_kupries Exp $
#
# Copyright (c) 2004 by Arjen Markus
# All rights reserved.
#
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.4;# statistics,linalg!
testsNeedTcltest 2.1
support {
useLocal math.tcl math
useLocal constants.tcl math::constants
useLocal linalg.tcl math::linearalgebra
useLocal statistics.tcl math::statistics
useLocal polynomials.tcl math::polynomials
}
testing {
useLocal special.tcl math::special
}
# -------------------------------------------------------------------------
#
# Expect an accuracy of at least four decimals
#
proc matchNumbers {expected actual} {
set match 1
foreach a $actual e $expected {
if {abs($a-$e) > 1.0e-4} {
set match 0
break
}
}
return $match
}
#
# Expect an accuracy of some three decimals (Fresnel)
#
proc matchFresnel {expected actual} {
set match 1
foreach a $actual e $expected {
if {abs($a-$e) > 2.0e-3} {
set match 0
break
}
}
return $match
}
customMatch numbers matchNumbers
customMatch numbers-fresnel matchFresnel
test "Erf-1.0" "Values of the error function" \
-match numbers -body {
set result {}
foreach x {0.0 0.1 0.2 0.5 1.0 2.0 -0.1 -0.2 -0.5 -1.0 -2.0} {
lappend result [::math::special::erf $x]
}
set result
} -result {0.0 0.1124629 0.2227026 0.5204999 0.8427008 0.9953227
-0.1124629 -0.2227026 -0.5204999 -0.8427008 -0.9953227}
proc make_erfc {erf_values} {
set result {}
foreach v $erf_values {
lappend result [expr {1.0-$v}]
}
return $result
}
test "Erf-1.1" "Values of the complementary error function" \
-match numbers -body {
set result {}
foreach x {0.0 0.1 0.2 0.5 1.0 2.0 -0.1 -0.2 -0.5 -1.0 -2.0} {
lappend result [::math::special::erfc $x]
}
set result
} -result [make_erfc {0.0 0.1124629 0.2227026 0.5204999 0.8427008 0.9953227
-0.1124629 -0.2227026 -0.5204999 -0.8427008 -0.9953227}]
test "Fresnel-1.0" "Values of the Fresnel C intergral" \
-match numbers-fresnel -body {
set result {}
foreach x {0.0 0.1 0.2 0.5 1.0 1.5 2.0 3.0 4.0 5.0} {
lappend result [::math::special::fresnel_C $x]
}
set result
} -result {0.0 0.09999 0.19992 0.49234 0.77989 0.44526
0.48825 0.60572 0.49842 0.56363}
test "Fresnel-1.1" "Values of the Fresnel S intergral" \
-match numbers-fresnel -body {
set result {}
foreach x {0.0 0.1 0.2 0.5 1.0 1.5 2.0 3.0 4.0 5.0} {
lappend result [::math::special::fresnel_S $x]
}
set result
} -result {0.0 0.00052 0.00419 0.06473 0.43826 0.69750
0.34342 0.49631 0.42052 0.49919}
# No tests for sinc yet
# End of test cases
testsuiteCleanup
|