This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathydf_test.go
56 lines (53 loc) · 1.84 KB
/
ydf_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
package yolp
import (
"encoding/xml"
"testing"
)
func TestUnmarshalCoordinates(t *testing.T) {
var c Coordinates
err := xml.Unmarshal([]byte("<Coordinates>35.62172852580437,139.6999476850032</Coordinates>"), &c)
if err != nil {
t.Errorf("Got error %v", err)
}
Test{35.62172852580437, c.Latitude}.Compare(t)
Test{139.6999476850032, c.Longitude}.Compare(t)
err = xml.Unmarshal([]byte("<Coordinates>35.62172852580437,---</Coordinates>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`strconv.ParseFloat: parsing "---": invalid syntax`, err.Error()}.Compare(t)
err = xml.Unmarshal([]byte("<Coordinates>---,139.6999476850032</Coordinates>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`strconv.ParseFloat: parsing "---": invalid syntax`, err.Error()}.Compare(t)
err = xml.Unmarshal([]byte("<Coordinates>---</Coordinates>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`Invalid format ---`, err.Error()}.Compare(t)
}
func TestUnmarshalRadius(t *testing.T) {
var c Radius
err := xml.Unmarshal([]byte("<Radius>0.01,0.02</Radius>"), &c)
if err != nil {
t.Errorf("Got error %v", err)
}
Test{0.01, c.Horizontal}.Compare(t)
Test{0.02, c.Vertical}.Compare(t)
err = xml.Unmarshal([]byte("<Radius>0.01,---</Radius>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`strconv.ParseFloat: parsing "---": invalid syntax`, err.Error()}.Compare(t)
err = xml.Unmarshal([]byte("<Radius>---,0.02</Radius>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`strconv.ParseFloat: parsing "---": invalid syntax`, err.Error()}.Compare(t)
err = xml.Unmarshal([]byte("<Radius>---</Radius>"), &c)
if err == nil {
t.Errorf("Expected not nil but got nil: %v", c)
}
Test{`Invalid format ---`, err.Error()}.Compare(t)
}