示例#1
0
func (s *S) TestEncodePlace(c *C) {
	var tweet ts.Tweet
	tweet.Place = &ts.Place{
		Attributes: map[string]interface{}{
			"foo": "bar",
		},
		BoundingBox: ts.Box{
			Points: []ts.Point{
				ts.Point{1.0, 2.5},
				ts.Point{3.4, 4.1},
			},
		},
	}
	data := decodeJson(marshal(tweet))
	place := data["place"].(map[string]interface{})

	box := place["bounding_box"].(map[string]interface{})
	c.Assert(box["type"], Equals, "Polygon")

	points := box["coordinates"].([]interface{})[0].([]interface{})
	p1 := points[0].([]interface{})
	p2 := points[1].([]interface{})
	c.Assert(p1[0], Equals, 2.5)
	c.Assert(p1[1], Equals, 1.0)
	c.Assert(p2[0], Equals, 4.1)
	c.Assert(p2[1], Equals, 3.4)
}
示例#2
0
func (s *S) TestEncodeCoordinates(c *C) {
	var tweet ts.Tweet
	tweet.Coordinates = &ts.Point{ts.Latitude(10.1), ts.Longitude(-12.5)}
	data := decodeJson(marshal(tweet))
	coords := data["coordinates"].(map[string]interface{})
	points := coords["coordinates"].([]interface{})
	c.Assert(points[0], Equals, -12.5)
	c.Assert(points[1], Equals, 10.1)
}