Skip to content

Commit

Permalink
Add tests for Union function
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Dec 14, 2023
1 parent b432e6b commit 4ca164c
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/data/Union/MandatoryConstraintThis.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" VERSION "2023-12-13" =
IMPORTS GeoW_FunctionsExt;

DOMAIN
!!@CRS=EPSG:2056
CHKoord = COORD 2460000.000 .. 2870000.000 [INTERLIS.m],
1045000.000 .. 1310000.000 [INTERLIS.m],
ROTATION 2 -> 1;

Surface = SURFACE WITH (STRAIGHTS) VERTEX CHKoord WITHOUT OVERLAPS > 0.1;

TOPIC FunctionTestTopic =

CLASS BaseClass =
surfaceAttribute : BAG OF Surface;

MANDATORY CONSTRAINT falseConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute, UNDEFINED), UNDEFINED) > 3;

MANDATORY CONSTRAINT oneInnerRingConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(THIS->surfaceAttribute, UNDEFINED), UNDEFINED) == 1;

END BaseClass;

END FunctionTestTopic;

END TestSuite.
31 changes: 31 additions & 0 deletions src/test/data/Union/SetConstraintAll.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" VERSION "2023-12-13" =
IMPORTS GeoW_FunctionsExt;

DOMAIN
!!@CRS=EPSG:2056
CHKoord = COORD 2460000.000 .. 2870000.000 [INTERLIS.m],
1045000.000 .. 1310000.000 [INTERLIS.m],
ROTATION 2 -> 1;

TOPIC FunctionTestTopic =

CLASS BaseClass =
surfaceAttribute : SURFACE WITH (STRAIGHTS) VERTEX CHKoord WITHOUT OVERLAPS > 0.1;

SET CONSTRAINT falseConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(ALL, "surfaceAttribute") > 3;
SET CONSTRAINT falseConstraintUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(ALL, "surfaceAttribute"), UNDEFINED) > 3;

SET CONSTRAINT trueConstraint:
GeoW_FunctionsExt.GetInnerRingsCount(ALL, "surfaceAttribute") == 1;
SET CONSTRAINT trueConstraintUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(ALL, "surfaceAttribute"), UNDEFINED) == 1;
END BaseClass;

END FunctionTestTopic;

END TestSuite.
29 changes: 29 additions & 0 deletions src/test/data/Union/SetConstraintMergedInnerRings.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" VERSION "2023-12-13" =
IMPORTS GeoW_FunctionsExt;

DOMAIN
Coord = COORD 0 .. 10 [INTERLIS.m],
0 .. 10 [INTERLIS.m],
ROTATION 2 -> 1;

TOPIC FunctionTestTopic =

CLASS BaseClass =
surfaceAttribute : SURFACE WITH (STRAIGHTS) VERTEX Coord WITHOUT OVERLAPS > 0.1;

!! Surfaces evaluated separately
SET CONSTRAINT innerRings:
GeoW_FunctionsExt.GetInnerRingsCount(ALL, "surfaceAttribute") == 2;

!! Surfaces evaluated as union (inner rings overlap in test data)
SET CONSTRAINT innerRingsUnion:
GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(ALL, "surfaceAttribute"), UNDEFINED) == 1;

END BaseClass;

END FunctionTestTopic;

END TestSuite.
101 changes: 101 additions & 0 deletions src/test/data/Union/TestData.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS" xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:GeoW_FunctionsExt="http://www.interlis.ch/xtf/2.4/GeoW_FunctionsExt"
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite">
<ili:headersection>
<ili:models>
<ili:model>GeoW_FunctionsExt</ili:model>
<ili:model>TestSuite</ili:model>
</ili:models>
<ili:sender>ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184</ili:sender>
</ili:headersection>
<ili:datasection>
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic">
<TestSuite:BaseClass ili:tid="0">
<TestSuite:surfaceAttribute> <!-- Surface with 1 inner ring -->
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2530000</geom:c1>
<geom:c2>1150000</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530010</geom:c1>
<geom:c2>1150000</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530010</geom:c1>
<geom:c2>1150010</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530000</geom:c1>
<geom:c2>1150010</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530000</geom:c1>
<geom:c2>1150000</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
<geom:interior>
<geom:polyline>
<geom:coord>
<geom:c1>2530003</geom:c1>
<geom:c2>1150003</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530006</geom:c1>
<geom:c2>1150003</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530006</geom:c1>
<geom:c2>1150006</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530003</geom:c1>
<geom:c2>1150006</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2530003</geom:c1>
<geom:c2>1150003</geom:c2>
</geom:coord>
</geom:polyline>
</geom:interior>
</geom:surface>
</TestSuite:surfaceAttribute>
</TestSuite:BaseClass>
<TestSuite:BaseClass ili:tid="1">
<TestSuite:surfaceAttribute> <!-- Surface without inner ring -->
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2646349.508</geom:c1>
<geom:c2>1249022.931</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2646353.508</geom:c1>
<geom:c2>1249022.926</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2646353.503</geom:c1>
<geom:c2>1249018.926</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2646349.503</geom:c1>
<geom:c2>1249018.931</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2646349.508</geom:c1>
<geom:c2>1249022.931</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:surfaceAttribute>
</TestSuite:BaseClass>
</TestSuite:FunctionTestTopic>
</ili:datasection>
</ili:transfer>
125 changes: 125 additions & 0 deletions src/test/data/Union/TestDataMergedInnerRings.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS" xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:GeoW_FunctionsExt="http://www.interlis.ch/xtf/2.4/GeoW_FunctionsExt"
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite">
<ili:headersection>
<ili:models>
<ili:model>GeoW_FunctionsExt</ili:model>
<ili:model>TestSuite</ili:model>
</ili:models>
<ili:sender>ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184</ili:sender>
</ili:headersection>
<ili:datasection>
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic">
<TestSuite:BaseClass ili:tid="0">
<TestSuite:surfaceAttribute> <!-- Surface with 1 inner square from (1,1) to (2,2) -->
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>10</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>10</geom:c1>
<geom:c2>10</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>10</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
<geom:interior>
<geom:polyline>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>2</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2</geom:c1>
<geom:c2>2</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
</geom:polyline>
</geom:interior>
</geom:surface>
</TestSuite:surfaceAttribute>
</TestSuite:BaseClass>
<TestSuite:BaseClass ili:tid="1">
<TestSuite:surfaceAttribute> <!-- Surface with one inner square from (1,1) to (4,4) -->
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>10</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>10</geom:c1>
<geom:c2>10</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>10</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>0</geom:c1>
<geom:c2>0</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
<geom:interior>
<geom:polyline>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>4</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>4</geom:c1>
<geom:c2>4</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>4</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>1</geom:c1>
<geom:c2>1</geom:c2>
</geom:coord>
</geom:polyline>
</geom:interior>
</geom:surface>
</TestSuite:surfaceAttribute>
</TestSuite:BaseClass>
</TestSuite:FunctionTestTopic>
</ili:datasection>
</ili:transfer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ch.geowerkstatt.ilivalidator.extensions.functions;

import ch.interlis.ili2c.Ili2cFailure;
import ch.interlis.iox.IoxException;
import com.vividsolutions.jts.util.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public final class UnionIoxPluginTest {
private static final String TEST_DATA = "Union/TestData.xtf";
private static final String TEST_DATA_MERGED_INNER_RINGS = "Union/TestDataMergedInnerRings.xtf";
private ValidationTestHelper vh;

@BeforeEach
void setUp() {
vh = new ValidationTestHelper();
vh.addFunction(new GetInnerRingsCountIoxPlugin());
vh.addFunction(new UnionIoxPlugin());
}

@Test
void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA}, new String[]{"Union/MandatoryConstraintThis.ili"});
Assert.equals(3, vh.getErrs().size());
AssertionHelper.assertConstraintErrors(vh, 2, "falseConstraint");
AssertionHelper.assertConstraintErrors(vh, 0, "0", "oneInnerRingConstraint");
AssertionHelper.assertConstraintErrors(vh, 1, "1", "oneInnerRingConstraint");
}

@Test
void setConstraintAll() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA}, new String[]{"Union/SetConstraintAll.ili"});
Assert.equals(2, vh.getErrs().size());
AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraint");
AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintUnion");
AssertionHelper.assertNoConstraintError(vh, "trueConstraint");
AssertionHelper.assertNoConstraintError(vh, "trueConstraintUnion");
}

@Test
void setConstraintMergedInnerRings() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA_MERGED_INNER_RINGS}, new String[]{"Union/SetConstraintMergedInnerRings.ili"});
Assert.equals(0, vh.getErrs().size());
AssertionHelper.assertNoConstraintError(vh, "innerRings");
AssertionHelper.assertNoConstraintError(vh, "innerRingsUnion");
}
}

0 comments on commit 4ca164c

Please sign in to comment.