File: elliptic.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (140 lines) | stat: -rw-r--r-- 3,990 bytes parent folder | download | duplicates (3)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- tcl -*-
# eliptic.test --
#    Test cases for the ::math::special package (Elliptic integrals)
#
# 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.
#
# Copyright (c) 2004 by Arjen Markus.  All rights reserved.
#
# RCS: @(#) $Id: elliptic.test,v 1.12 2007/08/21 17:33:00 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5;# statistics,linalg!
testsNeedTcltest 2.1

support {
    useLocal math.tcl        math
    useLocal constants.tcl   math::constants
    useLocal linalg.tcl      math::linearalgebra ;# for statistics
    useLocal statistics.tcl  math::statistics
    useLocal polynomials.tcl math::polynomials
}
testing {
    useLocal special.tcl math::special
}

# -------------------------------------------------------------------------

# 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 {
	#puts "abs($a-$e) = [expr {abs($a-$e)}]"
	if {abs($a-$e) > 0.1e-5} {
	    set match 0
	    break
	}
    }
    return $match
}

::tcltest::customMatch numbers matchNumbers

# -------------------------------------------------------------------------

test "Elliptic-1.0" "Complete elliptic integral of the first kind" \
    -match numbers -body {
	set result {}
	foreach k2 {0.0 0.1 0.2 0.4 0.5 0.7 0.8 0.95} {
	    set k [expr {sqrt($k2)}]
	    lappend result [::math::special::elliptic_K $k]
	}
	set result
    } -result {1.570796 1.612441 1.659624 1.777519 1.854075
	2.075363 2.257205 2.908337}

test "Elliptic-2.0" "Complete elliptic integral of the second kind" \
    -match numbers -body {
	set result {}
	foreach k2 {0.0 0.1 0.2 0.4 0.5 0.7 0.8 0.95} {
	    set k [expr {sqrt($k2)}]
	    lappend result [::math::special::elliptic_E $k]
	}
	set result
    } -result {1.570796 1.530758 1.489035 1.399392 1.350644
	1.241671 1.17849  1.060474}

# Jacobi elliptic functions: cn, sn and dn

set um_pairs {
0       0
0       0.1
0       0.8
0.1     0.1
0.1     0.2
0.1     0.5
0.1     0.7
0.1     0.8
0.2     0.01
0.2     0.1
0.2     0.5
0.3     0.01
0.3     0.1
0.3     0.5
0.4     0.01
0.5     0.01
0.5     0.1
0.6     0.1
0.7     0.1
0.8     0.1
0.8     0.5
0.9     0.01
0.9     0.1
0.9     0.5
0.99    0.5
}

test "Elliptic-3.1" "Jacobi elliptic cn function" \
    -match numbers -body {
	set result {}
	foreach {u m} $um_pairs {
	    set k [expr {sqrt($m)}]
	    lappend result [::math::special::cn $u $k]
	}
	set result
     } -result {1.000000 1.000000 1.000000 0.995006 0.995007 0.995012 0.995016 0.995017 0.980069 0.980093 0.980198 0.955350 0.955467
0.955986 0.921101 0.877678 0.878530 0.827220 0.768165 0.702062 0.722917 0.622418 0.629653 0.660895 0.602576}

test "Elliptic-3.2" "Jacobi elliptic sn function" \
    -match numbers -body {
	set result {}
	foreach {u m} $um_pairs {
	    set k [expr {sqrt($m)}]
	    lappend result [::math::special::sn $u $k]
	}
	set result
    } -result {0.000000 0.000000 0.000000 0.0998169 0.0998003 0.0997507 0.0997176 0.0997011 0.198656 0.198540 0.198022 0.295478 0.295098
0.293413 0.389323 0.479252 0.477687  0.561878  0.640252  0.712115  0.690935  0.782685 0.776876 0.750478 0.798062}

test "Elliptic-3.3" "Jacobi elliptic dn function" \
    -match numbers -body {
	set result {}
	foreach {u m} $um_pairs {
	    set k [expr {sqrt($m)}]
	    lappend result [::math::special::dn $u $k]
	}
	set result
    } -result {1.000000 1.000000 1.000000 0.999502 0.999003 0.997509 0.996514 0.996016 0.999803 0.998027 0.990148 0.999563 0.995636
0.978241 0.999242 0.998851 0.988525 0.984088 0.979289 0.974315 0.872528 0.996932 0.969354 0.847580 0.825560}

# End of test cases
testsuiteCleanup