Skip to content

Commit 5224d0d

Browse files
committed
Split the tests to know where to look for problems
1 parent 4093d32 commit 5224d0d

File tree

76 files changed

+15106
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+15106
-12
lines changed

tests/PolygonClipper.Tests/GenericTestCases.cs

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ namespace PolygonClipper.Tests;
1515

1616
public class GenericTestCases
1717
{
18-
public static IEnumerable<object[]> GetTestCases()
19-
=> TestData.Generic.GetFileNames().Select(x => new object[] { x });
18+
public static IEnumerable<object[]> GetTestCasesJs()
19+
=> TestData.Generic.GetFileNames("js").Select(x => new object[] { x });
20+
public static IEnumerable<object[]> GetTestCasesRust()
21+
=> TestData.Generic.GetFileNames("rust").Select(x => new object[] { x });
2022

2123
[Fact]
2224
public Polygon Profile()
@@ -34,8 +36,8 @@ public Polygon Profile()
3436
}
3537

3638
[Theory]
37-
[MemberData(nameof(GetTestCases))]
38-
public void GenericTestCase(string testCaseFile)
39+
[MemberData(nameof(GetTestCasesRust))]
40+
public void GenericTestCaseRust(string testCaseFile)
3941
{
4042
// Arrange
4143
FeatureCollection data = TestData.Generic.GetFeatureCollection(testCaseFile);
@@ -52,6 +54,54 @@ public void GenericTestCase(string testCaseFile)
5254
List<ExpectedResult> expectedResults = ExtractExpectedResults(data.Features.Skip(2).ToList(), data.Type);
5355
#pragma warning restore RCS1124 // Inline local variable
5456

57+
// ExpectedResult result = expectedResults[1];
58+
// Polygon actual = result.Operation(subject, clipping);
59+
// Assert.Equal(result.Coordinates.ContourCount, actual.ContourCount);
60+
61+
foreach (ExpectedResult result in expectedResults)
62+
{
63+
Polygon expected = result.Coordinates;
64+
Polygon actual = result.Operation(subject, clipping);
65+
66+
Assert.Equal(expected.ContourCount, actual.ContourCount);
67+
for (int i = 0; i < expected.ContourCount; i++)
68+
{
69+
// We don't test for holes here as the reference tests do not do so.
70+
Assert.Equal(expected[i].VertexCount, actual[i].VertexCount);
71+
for (int j = 0; j < expected[i].VertexCount; j++)
72+
{
73+
Vertex expectedVertex = expected[i].GetVertex(j);
74+
Vertex actualVertex = actual[i].GetVertex(j);
75+
Assert.Equal(expectedVertex.X, actualVertex.X, 3);
76+
Assert.Equal(expectedVertex.Y, actualVertex.Y, 3);
77+
}
78+
}
79+
}
80+
}
81+
82+
[Theory]
83+
[MemberData(nameof(GetTestCasesJs))]
84+
public void GenericTestCaseJs(string testCaseFile)
85+
{
86+
// Arrange
87+
FeatureCollection data = TestData.Generic.GetFeatureCollection(testCaseFile);
88+
89+
Assert.True(data.Features.Count >= 2, "Test case file must contain at least two features.");
90+
91+
IGeometryObject subjectGeometry = data.Features[0].Geometry;
92+
IGeometryObject clippingGeometry = data.Features[1].Geometry;
93+
94+
Polygon subject = ConvertToPolygon(subjectGeometry);
95+
Polygon clipping = ConvertToPolygon(clippingGeometry);
96+
97+
#pragma warning disable RCS1124 // Inline local variable
98+
List<ExpectedResult> expectedResults = ExtractExpectedResults(data.Features.Skip(2).ToList(), data.Type);
99+
#pragma warning restore RCS1124 // Inline local variable
100+
101+
// ExpectedResult result = expectedResults[1];
102+
// Polygon actual = result.Operation(subject, clipping);
103+
// Assert.Equal(result.Coordinates.ContourCount, actual.ContourCount);
104+
55105
foreach (ExpectedResult result in expectedResults)
56106
{
57107
Polygon expected = result.Coordinates;
@@ -89,12 +139,10 @@ private static Polygon ConvertToPolygon(IGeometryObject geometry)
89139

90140
polygon.Push(contour);
91141

92-
bool isLinear = ring.IsLinearRing();
93-
94-
if (!ring.IsClosed())
95-
{
96-
contour.AddVertex(contour.GetVertex(0));
97-
}
142+
// if (!ring.IsClosed())
143+
// {
144+
// contour.AddVertex(contour.GetVertex(0));
145+
// }
98146
}
99147

100148
return polygon;

tests/PolygonClipper.Tests/TestData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ private static string GetGeoJsonPath(string fileName)
2121

2222
public static class Generic
2323
{
24-
public static IEnumerable<string> GetFileNames()
24+
public static IEnumerable<string> GetFileNames(string subFolder)
2525
{
26-
DirectoryInfo info = new(Path.Combine(TestEnvironment.GeoJsonTestDataFullPath, nameof(Generic)));
26+
DirectoryInfo info = new(Path.Combine(TestEnvironment.GeoJsonTestDataFullPath, nameof(Generic), subFolder));
2727
foreach (FileInfo file in info.EnumerateFiles("*.geojson"))
2828
{
2929
yield return file.Name;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"features": [
3+
{
4+
"geometry": {
5+
"coordinates": [
6+
[
7+
[-1, 1],
8+
[1, 1],
9+
[1, -1],
10+
[-1, -1],
11+
[-1, -0.9],
12+
[0.9, -0.9],
13+
[0.9, 0.9],
14+
[-1, 0.9],
15+
[-1, 1]
16+
]
17+
],
18+
"type": "Polygon"
19+
},
20+
"properties": {},
21+
"type": "Feature"
22+
},
23+
{
24+
"geometry": {
25+
"coordinates": [[[-1, 1], [-0.9, 1], [-0.9, -1], [-1, -1], [-1, 1]]],
26+
"type": "Polygon"
27+
},
28+
"properties": {},
29+
"type": "Feature"
30+
},
31+
{
32+
"geometry": {
33+
"coordinates": [
34+
[
35+
[
36+
[-1, -1],
37+
[-0.9, -1],
38+
[1, -1],
39+
[1, 1],
40+
[-0.9, 1],
41+
[-1, 1],
42+
[-1, 0.9],
43+
[-1, -0.9],
44+
[-1, -1]
45+
],
46+
[[-0.9, -0.9], [0.9, -0.9], [0.9, 0.9], [-0.9, 0.9], [-0.9, -0.9]]
47+
]
48+
],
49+
"type": "MultiPolygon"
50+
},
51+
"properties": {"operation": "union"},
52+
"type": "Feature"
53+
}
54+
],
55+
"type": "FeatureCollection"
56+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"features": [
3+
{
4+
"geometry": {
5+
"coordinates": [
6+
[
7+
[355, 139],
8+
[420, 202],
9+
[384, 237],
10+
[353, 205],
11+
[330, 230],
12+
[330, 230],
13+
[291, 197]
14+
]
15+
],
16+
"type": "Polygon"
17+
},
18+
"properties": {},
19+
"type": "Feature"
20+
},
21+
{
22+
"geometry": {
23+
"coordinates": [
24+
[
25+
[355, 139],
26+
[420, 202],
27+
[384, 237],
28+
[353, 205],
29+
[330, 230],
30+
[330, 230],
31+
[291, 197]
32+
]
33+
],
34+
"type": "Polygon"
35+
},
36+
"properties": {},
37+
"type": "Feature"
38+
},
39+
{
40+
"geometry": {
41+
"coordinates": [
42+
[
43+
[
44+
[291, 197],
45+
[330, 230],
46+
[353, 205],
47+
[384, 237],
48+
[420, 202],
49+
[355, 139]
50+
]
51+
]
52+
],
53+
"type": "MultiPolygon"
54+
},
55+
"properties": {
56+
"operation": "intersection",
57+
"comment": "This test case is currently weird, because the rings aren't closed, so the operation doesn't make sense."
58+
},
59+
"type": "Feature"
60+
}
61+
],
62+
"type": "FeatureCollection"
63+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"features": [
3+
{
4+
"geometry": {
5+
"coordinates": [
6+
[
7+
[
8+
[0.55, 0.55],
9+
[0.55, 1.45],
10+
[1.45, 1.45],
11+
[1.45, 0.55],
12+
[0.55, 0.55]
13+
]
14+
],
15+
[
16+
[
17+
[1.55, 1.55],
18+
[1.55, 2.45],
19+
[2.45, 2.45],
20+
[2.45, 1.55],
21+
[1.55, 1.55]
22+
]
23+
]
24+
],
25+
"type": "MultiPolygon"
26+
},
27+
"properties": {},
28+
"type": "Feature"
29+
},
30+
{
31+
"geometry": {
32+
"coordinates": [
33+
[
34+
[
35+
[0.55, 1.55],
36+
[0.55, 2.45],
37+
[1.45, 2.45],
38+
[1.45, 1.55],
39+
[0.55, 1.55]
40+
]
41+
],
42+
[
43+
[
44+
[1.55, 0.55],
45+
[1.55, 1.45],
46+
[2.45, 1.45],
47+
[2.45, 0.55],
48+
[1.55, 0.55]
49+
]
50+
]
51+
],
52+
"type": "MultiPolygon"
53+
},
54+
"properties": {},
55+
"type": "Feature"
56+
},
57+
{
58+
"geometry": {
59+
"coordinates": [
60+
[
61+
[
62+
[0.55, 0.55],
63+
[1.45, 0.55],
64+
[1.45, 1.45],
65+
[0.55, 1.45],
66+
[0.55, 0.55]
67+
]
68+
],
69+
[
70+
[
71+
[0.55, 1.55],
72+
[1.45, 1.55],
73+
[1.45, 2.45],
74+
[0.55, 2.45],
75+
[0.55, 1.55]
76+
]
77+
],
78+
[
79+
[
80+
[1.55, 0.55],
81+
[2.45, 0.55],
82+
[2.45, 1.45],
83+
[1.55, 1.45],
84+
[1.55, 0.55]
85+
]
86+
],
87+
[
88+
[
89+
[1.55, 1.55],
90+
[2.45, 1.55],
91+
[2.45, 2.45],
92+
[1.55, 2.45],
93+
[1.55, 1.55]
94+
]
95+
]
96+
],
97+
"type": "MultiPolygon"
98+
},
99+
"properties": {"operation": "union"},
100+
"type": "Feature"
101+
}
102+
],
103+
"type": "FeatureCollection"
104+
}

0 commit comments

Comments
 (0)