Skip to content

Commit f7b2aa7

Browse files
Improve tests
1 parent 4397d79 commit f7b2aa7

File tree

1 file changed

+52
-38
lines changed

1 file changed

+52
-38
lines changed

application/src/test/java/org/opentripplanner/gtfs/mapping/CompactShapeTest.java

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,73 @@ class CompactShapeTest {
1111

1212
@Test
1313
void simple() {
14-
var builder = new CompactShape();
14+
var shape = new CompactShape();
1515

16-
builder.addPoint(shapePoint(1, 1, 2));
17-
builder.addPoint(shapePoint(2, 2, 2));
18-
builder.addPoint(shapePoint(3, 3, 3));
19-
builder.addPoint(shapePoint(4, 4, 4));
16+
shape.addPoint(shapePoint(1, 1, 2));
17+
shape.addPoint(shapePoint(2, 2, 2));
18+
shape.addPoint(shapePoint(3, 3, 3));
19+
shape.addPoint(shapePoint(4, 4, 4));
2020

21-
var points = ImmutableList.copyOf(builder);
21+
var points = ImmutableList.copyOf(shape);
22+
23+
assertEquals("[1 (1.0, 2.0), 2 (2.0, 2.0), 3 (3.0, 3.0), 4 (4.0, 4.0)]", points.toString());
24+
}
25+
26+
@Test
27+
void outOfSequence() {
28+
var shape = new CompactShape();
29+
30+
shape.addPoint(shapePoint(4, 4, 4));
31+
shape.addPoint(shapePoint(1, 1, 2));
32+
shape.addPoint(shapePoint(3, 3, 3));
33+
shape.addPoint(shapePoint(2, 2, 2));
34+
35+
var points = ImmutableList.copyOf(shape);
2236

2337
assertEquals("[1 (1.0, 2.0), 2 (2.0, 2.0), 3 (3.0, 3.0), 4 (4.0, 4.0)]", points.toString());
2438
}
2539

2640
@Test
2741
void hole() {
28-
var builder = new CompactShape();
42+
var shape = new CompactShape();
2943

3044
var p1 = shapePoint(1, 1.0, 2.0);
3145
var p2 = shapePoint(2, 3.0, 4.0);
3246
var p3 = shapePoint(10, 3.0, 4.0);
3347

34-
builder.addPoint(p1);
35-
builder.addPoint(p2);
36-
builder.addPoint(p3);
48+
shape.addPoint(p1);
49+
shape.addPoint(p2);
50+
shape.addPoint(p3);
3751

38-
var points = ImmutableList.copyOf(builder);
52+
var points = ImmutableList.copyOf(shape);
3953

4054
assertEquals("[1 (1.0, 2.0), 2 (3.0, 4.0), 10 (3.0, 4.0)]", points.toString());
4155
}
4256

4357
@Test
4458
void extendLatLon() {
45-
var builder = new CompactShape();
59+
var shape = new CompactShape();
4660

47-
builder.addPoint(shapePoint(1, 1, 1));
48-
builder.addPoint(shapePoint(2, 2, 2));
49-
builder.addPoint(shapePoint(10, 3, 3));
50-
builder.addPoint(shapePoint(51, 4, 4));
61+
shape.addPoint(shapePoint(1, 1, 1));
62+
shape.addPoint(shapePoint(2, 2, 2));
63+
shape.addPoint(shapePoint(10, 3, 3));
64+
shape.addPoint(shapePoint(51, 4, 4));
5165

52-
var points = ImmutableList.copyOf(builder);
66+
var points = ImmutableList.copyOf(shape);
5367

5468
assertEquals("[1 (1.0, 1.0), 2 (2.0, 2.0), 10 (3.0, 3.0), 51 (4.0, 4.0)]", points.toString());
5569
}
5670

5771
@Test
5872
void shapeDist() {
59-
var builder = new CompactShape();
73+
var shape = new CompactShape();
6074

61-
builder.addPoint(shapePoint(1, 1, 1, 0d));
62-
builder.addPoint(shapePoint(2, 2, 2, 1d));
63-
builder.addPoint(shapePoint(10, 3, 3, 2d));
64-
builder.addPoint(shapePoint(51, 4, 4));
75+
shape.addPoint(shapePoint(1, 1, 1, 0d));
76+
shape.addPoint(shapePoint(2, 2, 2, 1d));
77+
shape.addPoint(shapePoint(10, 3, 3, 2d));
78+
shape.addPoint(shapePoint(51, 4, 4));
6579

66-
var points = ImmutableList.copyOf(builder);
80+
var points = ImmutableList.copyOf(shape);
6781

6882
assertEquals(
6983
"[1 (1.0, 1.0) dist=0.0, 2 (2.0, 2.0) dist=1.0, 10 (3.0, 3.0) dist=2.0, 51 (4.0, 4.0)]",
@@ -73,16 +87,16 @@ void shapeDist() {
7387

7488
@Test
7589
void holeInDistTraveled() {
76-
var builder = new CompactShape();
90+
var shape = new CompactShape();
7791

78-
builder.addPoint(shapePoint(1, 1, 1, 1d));
79-
builder.addPoint(shapePoint(2, 2, 2, 2d));
80-
builder.addPoint(shapePoint(10, 3, 3, 4d));
81-
builder.addPoint(shapePoint(51, 4, 4));
82-
builder.addPoint(shapePoint(102, 5, 5, 10d));
83-
builder.addPoint(shapePoint(150, 6, 6));
92+
shape.addPoint(shapePoint(1, 1, 1, 1d));
93+
shape.addPoint(shapePoint(2, 2, 2, 2d));
94+
shape.addPoint(shapePoint(51, 4, 4));
95+
shape.addPoint(shapePoint(102, 5, 5, 10d));
96+
shape.addPoint(shapePoint(150, 6, 6));
97+
shape.addPoint(shapePoint(10, 3, 3, 4d));
8498

85-
var points = ImmutableList.copyOf(builder);
99+
var points = ImmutableList.copyOf(shape);
86100

87101
assertEquals(
88102
"[1 (1.0, 1.0) dist=1.0, 2 (2.0, 2.0) dist=2.0, 10 (3.0, 3.0) dist=4.0, 51 (4.0, 4.0), 102 (5.0, 5.0) dist=10.0, 150 (6.0, 6.0)]",
@@ -92,15 +106,15 @@ void holeInDistTraveled() {
92106

93107
@Test
94108
void zero() {
95-
var builder = new CompactShape();
109+
var shape = new CompactShape();
96110

97-
builder.addPoint(shapePoint(0, 1, 1, 1d));
98-
builder.addPoint(shapePoint(9, 2, 2, 2d));
99-
builder.addPoint(shapePoint(10, 3, 3, 4d));
100-
builder.addPoint(shapePoint(50, 4, 4, 5d));
101-
builder.addPoint(shapePoint(51, 5, 5, 6d));
111+
shape.addPoint(shapePoint(0, 1, 1, 1d));
112+
shape.addPoint(shapePoint(9, 2, 2, 2d));
113+
shape.addPoint(shapePoint(10, 3, 3, 4d));
114+
shape.addPoint(shapePoint(50, 4, 4, 5d));
115+
shape.addPoint(shapePoint(51, 5, 5, 6d));
102116

103-
var points = ImmutableList.copyOf(builder);
117+
var points = ImmutableList.copyOf(shape);
104118

105119
assertEquals(
106120
"[0 (1.0, 1.0) dist=1.0, 9 (2.0, 2.0) dist=2.0, 10 (3.0, 3.0) dist=4.0, 50 (4.0, 4.0) dist=5.0, 51 (5.0, 5.0) dist=6.0]",

0 commit comments

Comments
 (0)