Skip to content

Commit 6676eeb

Browse files
Merge pull request #255 from ie3-institute/to/#254-is-between-test
refactor test
2 parents 324ed89 + 7cd8bf1 commit 6676eeb

File tree

1 file changed

+62
-18
lines changed

1 file changed

+62
-18
lines changed

src/test/scala/edu/ie3/util/geo/RichGeometriesSpec.scala

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.scalatest.matchers.should.Matchers
2222
import org.scalatest.wordspec.AnyWordSpecLike
2323
import tech.units.indriya.quantity.Quantities
2424
import tech.units.indriya.unit.Units.METRE
25+
import org.scalatest.prop.TableDrivenPropertyChecks._
2526

2627
import scala.util.{Failure, Success}
2728

@@ -42,24 +43,67 @@ class RichGeometriesSpec extends Matchers with AnyWordSpecLike {
4243
}
4344

4445
"check if a coordinate is between two others" in {
45-
val coordinateA = buildCoordinate(10, 5)
46-
val coordinateB = buildCoordinate(20, 5)
47-
val coordinateBetween = buildCoordinate(15, 5)
48-
val coordinateNotExactlyBetween = buildCoordinate(16, 5.005)
49-
val coordinateNotBetween = buildCoordinate(15, 6)
50-
51-
coordinateBetween.isBetween(coordinateA, coordinateB) shouldBe true
52-
coordinateBetween.isBetween(coordinateB, coordinateA) shouldBe true
53-
coordinateNotExactlyBetween.isBetween(
54-
coordinateA,
55-
coordinateB
56-
) shouldBe false
57-
coordinateNotExactlyBetween.isBetween(
58-
coordinateA,
59-
coordinateB,
60-
1e-5
61-
) shouldBe true
62-
coordinateNotBetween.isBetween(coordinateB, coordinateA) shouldBe false
46+
val coordinates = Table(
47+
(
48+
"coordinateA",
49+
"coordinateB",
50+
"maybeCoordinateBetween",
51+
"epsilon",
52+
"isBetween"
53+
),
54+
(
55+
buildCoordinate(10, 5),
56+
buildCoordinate(20, 5),
57+
buildCoordinate(15, 5),
58+
1e-12,
59+
true
60+
),
61+
(
62+
buildCoordinate(20, 5),
63+
buildCoordinate(10, 5),
64+
buildCoordinate(15, 5),
65+
1e-12,
66+
true
67+
),
68+
(
69+
buildCoordinate(10, 5),
70+
buildCoordinate(20, 5),
71+
buildCoordinate(16, 5.005),
72+
1e-12,
73+
false
74+
),
75+
(
76+
buildCoordinate(7.4065, 51.538),
77+
buildCoordinate(7.4265, 51.578),
78+
buildCoordinate(7.423473617185907, 51.57194723437181),
79+
1e-12,
80+
false
81+
),
82+
(
83+
buildCoordinate(7.4065, 51.538),
84+
buildCoordinate(7.4265, 51.578),
85+
buildCoordinate(7.423473617185907, 51.57194723437181),
86+
1e-8,
87+
true
88+
)
89+
)
90+
91+
forAll(coordinates) {
92+
(
93+
coordinateA: Coordinate,
94+
coordinateB: Coordinate,
95+
maybeCoordinateBetwee: Coordinate,
96+
epsilon: Double,
97+
isBetween: Boolean
98+
) =>
99+
{
100+
maybeCoordinateBetwee.isBetween(
101+
coordinateA,
102+
coordinateB,
103+
epsilon
104+
) shouldBe isBetween
105+
}
106+
}
63107
}
64108

65109
"transform to a point correctly" in {

0 commit comments

Comments
 (0)