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
|
# constants.test --
# Test cases for the ::math::constants package
#
# 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: constants.test,v 1.6 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 math::constants."
puts " Requiring tcltest 2.1, have [package present tcltest]"
return
}
}
source [file join [file dirname [info script]] constants.tcl]
package require math::constants
#
# Test: do we get the constants into our namespace?
#
test "Constants-1.0" "Get constants into our namespace" -body {
::math::constants::constants pi e
expr {[info exists pi] && [info exists e]}
} -result 1
test "Constants-1.1" "Get constants with the right values" -body {
#
# Only needed once!
#
#::math::constants::constants pi e
set result1 [expr {abs($pi-4.0*atan(1.0))<1.0e-10?1:0}]
set result2 [expr {abs($e-exp(1.0))<1.0e-10?1:0}]
expr {$result1+$result2}
# Note: this should enough accuracy!
} -result 2
#
# No tests for print-constants defined ...
#
# End of test cases
tcltest::cleanupTests
|