-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_test.go
70 lines (61 loc) · 1.83 KB
/
query_test.go
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
package panodata
import (
"math"
"net/url"
"testing"
)
func approxLatLonDist(lat1, lon1 float64, lat2, lon2 float64) float64 {
dLat, dLon := lat2-lat1, lon2-lon1
x, y := dLon*math.Cos(lat1), dLat
return rEarth * math.Sqrt(x*x+y*y)
}
func TestQueryRadius(t *testing.T) {
var lat, lon float64 = 45, 0
var radius float64 = 10
query := QueryRadius(lat, lon, radius)
if d := approxLatLonDist(lat, lon, query.MinLat, query.MinLon); d > radius*math.Sqrt(2) {
t.Error("dist (min) =", d, "want", radius*math.Sqrt(2))
}
if d := approxLatLonDist(lat, lon, query.MaxLat, query.MaxLon); d > radius*math.Sqrt(2) {
t.Error("dist (max) =", d, "want", radius*math.Sqrt(2))
}
}
func TestQueryURLDefaults(t *testing.T) {
// Test defaults
queryDefault := Query{}
urlDefault, err := url.Parse(queryDefault.URL())
if err != nil {
t.Fatal("Malformed URL: ", err)
}
if urlDefault.Scheme != "http" {
t.Error("Scheme =", urlDefault.Scheme, "want http")
}
if urlDefault.Host != "www.panoramio.com" {
t.Error("Host =", urlDefault.Host, "want www.panoramio.com")
}
if urlDefault.Path != "/map/get_panoramas.php" {
t.Error("Path =", urlDefault.Path, "want /map/get_panoramas.php")
}
params := urlDefault.Query()
if set := params.Get("set"); set != "full" {
t.Error("set =", set, "want full")
}
if size := params.Get("size"); size != "original" {
t.Error("size =", size, "want original")
}
if minx := params.Get("minx"); minx != "0" {
t.Error("minx =", minx, "want 0")
}
if miny := params.Get("miny"); miny != "0" {
t.Error("miny =", miny, "want 0")
}
if maxx := params.Get("maxx"); maxx != "0" {
t.Error("maxx =", maxx, "want maxx")
}
if maxy := params.Get("maxy"); maxy != "0" {
t.Error("maxy =", maxy, "want maxy")
}
if mapFilter := params.Get("mapfilter"); mapFilter != "false" {
t.Error("mapfilter =", mapFilter, "want false")
}
}