1# Command covered: geomap.  Console commands only.
2#
3#	This script file tests the commands in the tclgeomap package.  See the
4#	tclgeomap man page for a description of the package.  See the tcltest
5#	man page for a description of Tcl's testing proc's.
6#
7#  Copyright (c) 2004 Gordon D. Carrie.  All rights reserved.
8#
9#  Licensed under the Open Software License version 2.1
10#
11#  Please address questions and feedback to user0@tkgeomap.org
12#
13# @(#) $Id: tcl_geomap.test,v 1.4 2004/09/22 21:57:51 tkgeomap Exp $
14
15if {[lsearch [namespace children] ::tcltest] == -1} {
16    package require tcltest
17    namespace import ::tcltest::*
18}
19
20package require tclgeomap 2
21
22namespace eval geomap {
23
24test tclgeomap-1.1 {domainlon} {
25    set PI 3.14159265358979323846
26    set DEGPERRAD [expr {180.0 / $PI}]
27    set RADPERDEG [expr {$PI / 180.0}]
28    for {set errs {};set phi -800} {$phi <= 800} {incr phi} {
29	set phiL [domnlat $phi]
30	set phiS [expr {$DEGPERRAD * asin(sin($phi * $RADPERDEG))}]
31	set err [format {%.1f} [expr {$phiL - $phiS}]]
32	if {!([string match $err "0.0"] || [string match $err "-0.0"])} {
33	    lappend errs $err
34	}
35    }
36    set errs
37} {}
38
39test tclgeomap-1.2 {domainlon} {
40    foreach rLon {-135.0 -45.0 0.0 45.0 135.0} {
41	upvar 0 $rLon rLonArr
42
43	# Generate results manually
44
45	for {set i -400} {$i <= 400} {incr i} {
46	    if {$i < $rLon - 180.0} {
47		set rLonArr($i) [expr $i + 360.0]
48	    } elseif {$i > $rLon + 180.0} {
49		set rLonArr($i) [expr $i - 360.0]
50	    } else {
51		set rLonArr($i) $i
52	    }
53	}
54
55	# Check manual results against results of domnlon command
56
57	set rslt {}
58	for {set i -400} {$i <= 400} {incr i} {
59	    set i2 [domnlon $i $rLon]
60	    if {$i2 != $rLonArr($i)} {
61		lappend rslt \
62		"Domain of $rLon, longitude $i: got $i2 instead of $rLonArr($i)"
63	    }
64	}
65    }
66    set rslt
67} {}
68
69test tclgeomap-1.3 {gwchlon} {
70
71    # Generate results manually
72
73    for {set i -400} {$i <= 400} {incr i} {
74	if {$i < $rLon - 180.0} {
75	    set GwchLon($i) [expr $i + 360.0]
76	} elseif {$i > $rLon + 180.0} {
77	    set GwchLon($i) [expr $i - 360.0]
78	} else {
79	    set GwchLon($i) $i
80	}
81    }
82
83    # Check manual results against results of domnlon command
84
85    set rslt {}
86    for {set i -400} {$i <= 400} {incr i} {
87	set i2 [domnlon $i $rLon]
88	if {$i2 != $GwchLon($i)} {
89	    lappend rslt \
90	    "Domain of $rLon, longitude $i: got $i2 instead of $GwchLon($i)"
91	}
92    }
93    set rslt
94} {}
95
96test tclgeomap-1.4 {latlonok with large angle} {
97    latlonok [list 1e10 1e10]
98} {0}
99
100cleanupTests
101
102}
103