File: elliptic.test

package info (click to toggle)
tcllib 1.8-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,628 kB
  • ctags: 4,897
  • sloc: tcl: 88,012; sh: 7,856; ansic: 4,174; xml: 1,765; yacc: 753; perl: 84; f90: 84; makefile: 60; python: 33; ruby: 13; php: 11
file content (73 lines) | stat: -rwxr-xr-x 2,121 bytes parent folder | download
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
# 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.7 2005/09/28 04:51:22 andreas_kupries Exp $


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 elliptic 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]] "elliptic.tcl"]
package require math::constants

# 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}


# End of test cases
tcltest::cleanupTests