func (s *RethinkSuite) TestGeospatialDecodeGeometryPseudoType(c *test.C) { var response types.Geometry // setup coordinates coords := [][][]float64{ { {-122.423246, 37.779388}, {-122.423246, 37.329898}, {-121.88642, 37.329898}, {-121.88642, 37.329898}, {-122.423246, 37.779388}, }, } gt := "Polygon" res, err := Expr(map[string]interface{}{ "$reql_type$": "GEOMETRY", "type": "Polygon", "coordinates": coords, }).Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) // test shape if response.Type != gt { c.Errorf("expected [%v], instead [%v]", gt, response.Type) } // assert points are within threshold c.Assert(response, geometryEquals, "Polygon", coords) }
func (s *RethinkSuite) TestGeospatialPointDistanceRootKm(c *test.C) { var response float64 f := 734.125249602186 res, err := Distance(Point(-122.423246, 37.779388), Point(-117.220406, 32.719464), DistanceOpts{Unit: "km"}).Run(session) c.Assert(err, test.IsNil) err = res.One(&response) c.Assert(err, test.IsNil) if !kindaclose(response, f) { c.Errorf("the deviation between the compared floats is too great [%v:%v]", response, f) } }