petern48 commented on code in PR #741:
URL: https://github.com/apache/sedona-db/pull/741#discussion_r3035746581


##########
python/sedonadb/tests/functions/test_predicates.py:
##########
@@ -495,3 +495,55 @@ def test_st_relate(eng, geom1, geom2, expected):
         f"SELECT ST_Relate({geom_or_null(geom1)}, {geom_or_null(geom2)})",
         expected,
     )
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom1", "geom2", "pattern", "expected"),
+    [
+        (None, None, None, None),
+        ("POINT (0 0)", None, "FF0FFF0F2", None),
+        (None, "POINT (0 0)", "FF0FFF0F2", None),

Review Comment:
   ```suggestion
           (None, "POINT (0 0)", "FF0FFF0F2", None),
           ("POINT (0 0)", "POINT (0 0)", None, None),
   ```
   nice to test this variation too (only pattern is `NULL`)



##########
python/sedonadb/tests/functions/test_predicates.py:
##########
@@ -495,3 +495,55 @@ def test_st_relate(eng, geom1, geom2, expected):
         f"SELECT ST_Relate({geom_or_null(geom1)}, {geom_or_null(geom2)})",
         expected,
     )
+
+
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+    ("geom1", "geom2", "pattern", "expected"),
+    [
+        (None, None, None, None),
+        ("POINT (0 0)", None, "FF0FFF0F2", None),
+        (None, "POINT (0 0)", "FF0FFF0F2", None),
+        # Exact match — disjoint points
+        ("POINT (0 0)", "POINT (1 1)", "FF0FFF0F2", True),
+        # Exact match — point inside polygon
+        ("POINT (0.5 0.5)", "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 
"0FFFFF212", True),
+        # Pattern does not match — point on boundary vs interior pattern
+        ("POINT (0 0)", "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", "0FFFFF212", 
False),
+        # Polygon contains point — exact DE-9IM from polygon's perspective
+        (
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
+            "POINT (0.5 0.5)",
+            "0F2FF1FF2",
+            True,
+        ),
+        # Disjoint — does not match contains pattern
+        (
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
+            "POINT (5 5)",
+            "0F2FF1FF2",
+            False,
+        ),
+        # Touching polygons
+        (
+            "POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))",
+            "POLYGON ((2 0, 4 0, 4 2, 2 2, 2 0))",
+            "FF2F11212",
+            True,
+        ),
+        # Overlapping polygons match overlap pattern
+        (
+            "POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))",
+            "POLYGON ((1 1, 3 1, 3 3, 1 3, 1 1))",
+            "212101212",
+            True,
+        ),
+    ],
+)
+def test_st_relate_pattern(eng, geom1, geom2, pattern, expected):
+    eng = eng.create_or_skip()
+    pattern_sql = "NULL" if pattern is None else f"'{pattern}'"
+    eng.assert_query_result(
+        f"SELECT ST_Relate({geom_or_null(geom1)}, {geom_or_null(geom2)}, 
{pattern_sql})",

Review Comment:
   ```suggestion
       eng.assert_query_result(
           f"SELECT ST_Relate({geom_or_null(geom1)}, {geom_or_null(geom2)}, 
'{val_or_null(pattern)}')",
   ```
   
   nit: We have an [existing 
helper](https://github.com/Mehak3010/sedona-db/blob/2822b30680a7b46ddd12fd1f32eacb576a16abac/python/sedonadb/python/sedonadb/testing.py#L678-L692)
 for this :)



##########
python/sedonadb/tests/functions/test_predicates.py:
##########


Review Comment:
   Could we add a few more of these same test cases from `test_st_relate` as 
`True` cases for `test_st_relate_pattern`? e.g., we're missing a 
point-in-polygon-hole case and linestring and geometry collections cases, a few 
lines up.
   
   Maybe add a few more `False` cases for other predicates, since we only have 
two tests that return `False` at the moment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to