File: map_slippy.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (144 lines) | stat: -rw-r--r-- 4,560 bytes parent folder | download | duplicates (6)
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
141
142
143
144
# Tests for the map::slippy module.                           -*- tcl -*- 
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2010 Andreas Kupries
# All rights reserved.
#
# RCS: @(#) $Id: map_slippy.test,v 1.2 2011/03/24 20:33:34 andreas_kupries Exp $

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

package require tcltest

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

testsNeedTcl     8.4
testsNeedTcltest 2.1

support {
    use snit/snit.tcl      snit
    use math/math.tcl      math
    use math/constants.tcl math::constants
}
testing {
    useLocal map_slippy.tcl map::slippy
}

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

proc 4digits {args} {
    set res {}
    foreach arg $args {lappend res [expr (round(10000*$arg))/10000.0]}
    return $res
}

#
# Match floating point numbers to within 4 digits.
#

proc matchNumbers {expected actual} {
    set match 1
    foreach a $actual e $expected {
        if {abs($a-$e) > 1e-4} {
            set match 0
            break
        }
    }
    return $match
}

customMatch 4digits matchNumbers

# -------------------------------------------------------------------------
# Encoding tests
# -------------------------------------------------------------------------

test map-slippy-7.0 {tile 2geo} -body {
    ::map::slippy tile 2geo {11 504 775}
} -match 4digits -result {11.0 67.0674 -43.7695}

# -------------------------------------------------------------------------
# Converting between the three coordinate systems.
# -------------------------------------------------------------------------

foreach {n tile point geo tilei} {
    0  {0 0 0}     {0 0 0}     {0  85.0511287798 -180.0} {0 0 0}
    1  {0 1 1}     {0 256 256} {0 -85.0511287798  180.0} {0 0 1}
    2  {0 0.5 0.5} {0 128 128} {0 0 0}                   {0 0 0}
    3  {1 0 0}     {1 0 0}     {1  85.0511287798 -180.0} {1 0 0}
    4  {1 1 1}     {1 256 256} {1 0 0}                   {1 1 1}
    5  {1 0.5 0.5} {1 128 128} {1  66.5132604431  -90.0} {1 0 0}
    6  {1 2 2}     {1 512 512} {1 -85.0511287798  180.0} {1 1 2}
    7  {1 1.5 1.5} {1 384 384} {1 -66.5132604431   90.0} {1 1 1}
} {
    # The tilei results for .1/.6 are
    # |0 0 1| instead of |0 1 1|
    # |1 1 2|            |1 2 2|
    # due to round off. As a float is it shown as 1.0, internally it
    # is actually 0.9999...

    test map-slippy-8.$n {tile -> point} -body {
	::map::slippy tile 2point $tile
    } -match 4digits -result $point

    test map-slippy-9.$n {point -> tile} -body {
	::map::slippy point 2tile $point
    } -match 4digits -result $tile

    test map-slippy-10.$n {point -> tile -> point} -body {
	::map::slippy tile 2point [::map::slippy point 2tile $point]
    } -match 4digits -result $point

    test map-slippy-11.$n {tile -> point -> tile} -body {
	::map::slippy point 2tile [::map::slippy tile 2point $tile]
    } -match 4digits -result $tile

    test map-slippy-12.$n {tile -> geo} -body {
	::map::slippy tile 2geo $tile
    } -match 4digits -result $geo

    test map-slippy-13.$n {geo -> tile/float} -body {
	::map::slippy geo 2tile.float $geo
    } -match 4digits -result $tile

    test map-slippy-13a.$n {geo -> tile} -body {
	::map::slippy geo 2tile $geo
    } -match 4digits -result $tilei

    test map-slippy-14.$n {geo -> tile/float -> geo} -body {
	::map::slippy tile 2geo [::map::slippy geo 2tile.float $geo]
    } -match 4digits -result $geo

    test map-slippy-15.$n {tile/float -> geo -> tile/float} -body {
	::map::slippy geo 2tile.float [::map::slippy tile 2geo $tile]
    } -match 4digits -result $tile

    test map-slippy-16.$n {point -> geo} -body {
	::map::slippy point 2geo $point
    } -match 4digits -result $geo

    test map-slippy-17.$n {geo -> point} -body {
	::map::slippy geo 2point $geo
    } -match 4digits -result $point

    test map-slippy-18.$n {geo -> point -> geo} -body {
	::map::slippy point 2geo [::map::slippy geo 2point $geo]
    } -match 4digits -result $geo

    test map-slippy-19.$n {point -> geo -> point} -body {
	::map::slippy geo 2point [::map::slippy point 2geo $point]
    } -match 4digits -result $point
}

# -------------------------------------------------------------------------
testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End: