Skip to content

Commit

Permalink
Add remaining tests for new conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Sep 3, 2020
1 parent 48b884d commit 24ace6b
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/conversion/from_geo_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ mod tests {
use crate::{Geometry, Value};
use geo_types;
use geo_types::{
GeometryCollection, LineString, Line, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
Coordinate, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon, Rect, Triangle,
};

#[test]
Expand Down Expand Up @@ -334,6 +335,57 @@ mod tests {
}
}

#[test]
fn geo_triangle_conversion_test() {
let c1 = Coordinate { x: 0., y: 0. };
let c2 = Coordinate { x: 10., y: 20. };
let c3 = Coordinate { x: 20., y: -10. };

let triangle = Triangle(c1, c2, c3);

let geojson_polygon = Value::from(&triangle);

// Geo-types Polygon construction introduces an extra vertex: let's check it!
if let Value::Polygon(c) = geojson_polygon {
assert_almost_eq!(c1.x as f64, c[0][0][0], 1e-6);
assert_almost_eq!(c1.y as f64, c[0][0][1], 1e-6);
assert_almost_eq!(c2.x as f64, c[0][1][0], 1e-6);
assert_almost_eq!(c2.y as f64, c[0][1][1], 1e-6);
assert_almost_eq!(c3.x as f64, c[0][2][0], 1e-6);
assert_almost_eq!(c3.y as f64, c[0][2][1], 1e-6);
assert_almost_eq!(c1.x as f64, c[0][3][0], 1e-6);
assert_almost_eq!(c1.y as f64, c[0][3][1], 1e-6);
} else {
panic!("Not valid geometry {:?}", geojson_polygon);
}
}

#[test]
fn geo_rect_conversion_test() {
let c1 = Coordinate { x: 0., y: 0. };
let c2 = Coordinate { x: 10., y: 20. };

let rect = Rect::new(c1, c2);

let geojson_polygon = Value::from(&rect);

// Geo-types Polygon construction introduces an extra vertex: let's check it!
if let Value::Polygon(c) = geojson_polygon {
assert_almost_eq!(c1.x as f64, c[0][0][0], 1e-6);
assert_almost_eq!(c1.y as f64, c[0][0][1], 1e-6);
assert_almost_eq!(c1.x as f64, c[0][1][0], 1e-6);
assert_almost_eq!(c2.y as f64, c[0][1][1], 1e-6);
assert_almost_eq!(c2.x as f64, c[0][2][0], 1e-6);
assert_almost_eq!(c2.y as f64, c[0][2][1], 1e-6);
assert_almost_eq!(c2.x as f64, c[0][3][0], 1e-6);
assert_almost_eq!(c1.y as f64, c[0][3][1], 1e-6);
assert_almost_eq!(c1.x as f64, c[0][4][0], 1e-6);
assert_almost_eq!(c1.y as f64, c[0][4][1], 1e-6);
} else {
panic!("Not valid geometry {:?}", geojson_polygon);
}
}

#[test]
fn geo_multi_line_string_conversion_test() {
let p1 = Point::new(40.02f64, 116.34f64);
Expand Down

0 comments on commit 24ace6b

Please sign in to comment.