This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_test.go
133 lines (114 loc) · 3.09 KB
/
point_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
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
package kml
import (
// "encoding/xml"
"encoding/xml"
"testing"
// . "github.com/markxp/parser/kml"
)
func Test_XmlUnmarshal_Point_1(t *testing.T) {
raw := `
<?xml version="1.0" encoding="UTF-8"?>
<Point>
<coordinates>1.0,-1.0,+0.35</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
`
p := Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: "relativeToGround"}
var unmarshal Point
xml.Unmarshal([]byte(raw), &unmarshal)
if p != unmarshal {
t.Errorf("Unmarshal Point , raw data: %s\n, Expect %v\n, Result %v", raw, p, unmarshal)
} else {
t.Log("Test_XmlUnmarshal_Point_1 PASS")
}
}
func Test_XmlUnmarshal_Point_2(t *testing.T) {
raw := `
<Point>
<coordinates>1.0,-1.0,+0.35</coordinates>
</Point>
`
p := Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: ""}
var unmashal Point
xml.Unmarshal([]byte(raw), &unmashal)
if p != unmashal {
t.Errorf("Unmarshal Point , raw data: %s\n, Expect %#v\n, Result %#v", raw, p, unmashal)
} else {
t.Log("Test_XmlUnmarshal_Point_2 PASS")
}
}
// BUG: altitudeMode tag: either Mode is set to ""or not set.
// Marshal() shows the tag.
//
func Test_XmlMarshal_Point_1(t *testing.T) {
p := Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35"}
ans := `<Point><coordinates>1.0,-1.0,+0.35</coordinates><altitudeMode></altitudeMode></Point>`
raw, err := xml.Marshal(p)
if err == nil {
if string(raw) != string(ans) {
t.Logf("%#v \n\n %#v", string(ans), string(raw))
t.Errorf("(p *Point) Marshal ([]byte,error) failed. Byte comparsion")
} else {
t.Log("OK")
}
} else {
t.Errorf("(p *Point) Marshal ([]byte,error) failed. ")
}
}
func Test_Coordinates(t *testing.T) {
//
//<Point>
// <coordinates>1.0,-1.0,+0.35</coordinates>
//</Point>
//
p := Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: ""}
v, err := p.Coordinates()
if err != nil {
t.Errorf("func (p *Point) Coordinates() ([3]float64 ,error) failed.")
}
if len(v) != 3 {
t.Errorf("func (p *Point) Coordinates() ([3]float64 ,error) failed." +
" \"ArraSize\"")
}
ans := [3]float64{1.0, -1.0, 0.35}
for i := 0; i != len(v); i++ {
if v[i]-ans[i] > 0.00001 {
t.Errorf("func (p *Point) Coordinates() ([3]float64 failed, Transform Unaccurately")
}
}
}
func Test_SetCoordinates(t *testing.T) {
coord := [3]float64{10, -20, 0.00001}
p := Point{XMLName: xml.Name{Space: "", Local: "Point"},
CoordData: "1.0,-1.0,+0.35",
Mode: ""}
p.SetCoordinates(coord)
// Check (p.x, p.y, p.z)
if p.CoordData != "10,-20,0.00001" {
t.Errorf("%#v", p)
}
}
func Test_Point_Distance(t *testing.T) {
p1Raw := ` <Point>
<coordinates>121.04564687,24.77332218,0</coordinates>
</Point>`
p2Raw := ` <Point>
<coordinates>121.04581743,24.77330606,0</coordinates>
</Point>
`
var p1, p2 Point
e1 := xml.Unmarshal([]byte(p1Raw), &p1)
e2 := xml.Unmarshal([]byte(p2Raw), &p2)
if e1 != nil || e2 != nil {
t.Error("Distance() failed. unmashal error")
} else {
t.Log(p1.Distance(p2))
}
}