Skip to content

Commit

Permalink
Merge pull request #1224 from georust/mkirk/jts-test-runner-for-equal…
Browse files Browse the repository at this point in the history
…-topo

Include is_equal_topo tests from jts test suite
  • Loading branch information
michaelkirk authored Oct 10, 2024
2 parents b72383d + 4e35720 commit d0190ac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<test><op name="covers" arg1="A" arg2="B">true</op></test>
<test><op name="crosses" arg1="A" arg2="B">false</op></test>
<test><op name="disjoint" arg1="A" arg2="B">false</op></test>
<test><op name="equalsTopo" arg1="A" arg2="B">false</op></test>
<test><op name="equalsTopo" arg1="A" arg2="B">true</op></test>
<test><op name="intersects" arg1="A" arg2="B">true</op></test>
<test><op name="overlaps" arg1="A" arg2="B">false</op></test>
<test><op name="touches" arg1="A" arg2="B">false</op></test>
Expand Down
35 changes: 31 additions & 4 deletions jts-test-runner/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ pub struct ConvexHullInput {
pub(crate) expected: geo::Geometry,
}

#[derive(Debug, Deserialize)]
pub struct EqualsTopoInput {
pub(crate) arg1: String,
pub(crate) arg2: String,

#[serde(rename = "$value", deserialize_with = "deserialize_from_str")]
pub(crate) expected: bool,
}

#[derive(Debug, Deserialize)]
pub struct IntersectsInput {
pub(crate) arg1: String,
Expand Down Expand Up @@ -137,6 +146,9 @@ pub(crate) enum OperationInput {
#[serde(rename = "convexhull")]
ConvexHullInput(ConvexHullInput),

#[serde(rename = "equalsTopo")]
EqualsTopo(EqualsTopoInput),

#[serde(rename = "intersects")]
IntersectsInput(IntersectsInput),

Expand Down Expand Up @@ -182,6 +194,11 @@ pub(crate) enum Operation {
subject: Geometry,
expected: Geometry,
},
EqualsTopo {
a: Geometry,
b: Geometry,
expected: bool,
},
Intersects {
subject: Geometry,
clip: Geometry,
Expand Down Expand Up @@ -222,6 +239,19 @@ impl OperationInput {
expected: convex_hull_input.expected,
})
}
Self::EqualsTopo(equals_topo_input) => {
assert_eq!("A", equals_topo_input.arg1);
assert_eq!("B", equals_topo_input.arg2);
assert!(
case.b.is_some(),
"equalsTopo test case must contain geometry b"
);
Ok(Operation::EqualsTopo {
a: geometry.clone(),
b: case.b.clone().expect("no geometry b in case"),
expected: equals_topo_input.expected,
})
}
Self::IntersectsInput(input) => {
assert_eq!("A", input.arg1);
assert_eq!("B", input.arg2);
Expand All @@ -238,10 +268,7 @@ impl OperationInput {
Self::RelateInput(input) => {
assert_eq!("A", input.arg1);
assert_eq!("B", input.arg2);
assert!(
case.b.is_some(),
"intersects test case must contain geometry b"
);
assert!(case.b.is_some(), "relate test case must contain geometry b");
Ok(Operation::Relate {
a: geometry.clone(),
b: case.b.clone().expect("no geometry b in case"),
Expand Down
2 changes: 1 addition & 1 deletion jts-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod tests {
//
// We'll need to increase this number as more tests are added, but it should never be
// decreased.
let expected_test_count: usize = 2213;
let expected_test_count: usize = 2697;
let actual_test_count = runner.failures().len() + runner.successes().len();
match actual_test_count.cmp(&expected_test_count) {
Ordering::Less => {
Expand Down
18 changes: 17 additions & 1 deletion jts-test-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wkt::ToWkt;
use super::{input, Operation, Result};
use geo::algorithm::{BooleanOps, Contains, HasDimensions, Intersects, Within};
use geo::geometry::*;
use geo::GeoNum;
use geo::{GeoNum, Relate};

const GENERAL_TEST_XML: Dir = include_dir!("$CARGO_MANIFEST_DIR/resources/testxml/general");
const VALIDATE_TEST_XML: Dir = include_dir!("$CARGO_MANIFEST_DIR/resources/testxml/validate");
Expand Down Expand Up @@ -142,6 +142,22 @@ impl TestRunner {
self.successes.push(test_case);
}
}
Operation::EqualsTopo { a, b, expected } => {
let im = a.relate(b);
let actual = im.is_equal_topo();
if actual == *expected {
debug!("Passed: EqualsTopo was {actual}");
self.successes.push(test_case);
} else {
debug!("is_equal_topo was {actual}, but expected {expected}");
let error_description =
format!("is_equal_topo was {actual}, but expected {expected}");
self.failures.push(TestFailure {
test_case,
error_description,
});
}
}
Operation::Within {
subject,
target,
Expand Down

0 comments on commit d0190ac

Please sign in to comment.