Skip to content

Commit

Permalink
Test coverage improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sheinbergon committed Dec 19, 2022
1 parent 91071ae commit b70c8ef
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ public static void markHolderNotSet(final @Nonnull ValueHolder holder) {
((NullableVarCharHolder) holder).isSet = BIT_FALSE;
} else if (holder instanceof NullableVarBinaryHolder) {
((NullableVarBinaryHolder) holder).isSet = BIT_FALSE;
} else if (holder instanceof NullableFloat8Holder) {
((NullableFloat8Holder) holder).isSet = BIT_FALSE;
} else {
throw new IllegalArgumentException(
String.format("Unsupported value holder type - %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ internal class STAngle2LinesTests : GeometryMeasurementFunSpec.Binary<STAngle2Li
"LINESTRING(0 0, 0.2 0.5, 1 0)",
0.7853981633974483
)

testNullGeometryMeasurement(
"Calling ST_Angle on 2 LINESTRINGs, one of them is null",
"LINESTRING(0 0, 0.3 0.7, 1 1)",
null,
4326
)
}

override val function = STAngle2Lines().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ internal class STAngle3PointsTests : GeometryMeasurementFunSpec.Ternary<STAngle3
"POINT(20 0)",
4.71238898038469
)

testNullGeometryMeasurement(
"Calling ST_Angle on 3 POINTs, one of them is null",
"POINT(10 10)",
null,
"POINT(10 20)",
4326
)
}

override val function = STAngle3Points().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ internal class STBufferParametersTests : GeometryProcessingFunSpec<STBufferParam
function.radiusInput.value = 20.0
function.parametersInput.setUtf8("side=right")
}

testNullGeometryProcessing(
"Calling ST_Buffer (with parameters string) on a NULL input"
) {
function.radiusInput.value = 29.1
function.parametersInput.setUtf8("side=right")
}
}

override val function = STBufferParameters().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ internal class STBufferTests : GeometryProcessingFunSpec<STBuffer>() {
1 0))
""".trimIndent()
) { function.radiusInput.value = 1.0 }

testNullGeometryProcessing(
"Calling ST_Buffer on a NULL input"
)
}

override val function = STBuffer().apply {
Expand Down
34 changes: 34 additions & 0 deletions src/test/kotlin/org/sheinbergon/dremio/udf/gis/STIsSimpleTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.sheinbergon.dremio.udf.gis

import org.apache.arrow.vector.holders.NullableBitHolder
import org.apache.arrow.vector.holders.NullableVarBinaryHolder
import org.sheinbergon.dremio.udf.gis.spec.GeometryAccessorFunSpec

internal class STIsSimpleTests : GeometryAccessorFunSpec<STIsSimple, NullableBitHolder>() {

init {
testGeometryAccessor(
"Calling ST_IsSimple on a self-intersecting Polygon",
"POLYGON((1 2, 3 4, 5 6, 1 2))",
false
)

testGeometryAccessor(
"Calling ST_IsSimple on a simple LineString",
"LINESTRING(2 1, 1 3, 6 6, 5 7, 5 6)",
true
)

testNullGeometryAccessor(
"Calling ST_IsSimple on null input returns false",
)
}

override val function = STIsSimple().apply {
binaryInput = NullableVarBinaryHolder()
output = NullableBitHolder()
}

override val STIsSimple.wkbInput: NullableVarBinaryHolder get() = function.binaryInput
override val STIsSimple.output: NullableBitHolder get() = function.output
}
37 changes: 37 additions & 0 deletions src/test/kotlin/org/sheinbergon/dremio/udf/gis/STSimplifyTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.sheinbergon.dremio.udf.gis

import org.apache.arrow.vector.holders.Float8Holder
import org.apache.arrow.vector.holders.NullableVarBinaryHolder
import org.sheinbergon.dremio.udf.gis.spec.GeometryProcessingFunSpec
import org.sheinbergon.dremio.udf.gis.util.allocateBuffer
import org.sheinbergon.dremio.udf.gis.util.reset

internal class STSimplifyTests : GeometryProcessingFunSpec<STSimplify>() {

init {

beforeEach {
function.toleranceInput.reset()
}

testGeometryProcessing(
name = "Calling ST_Simplify on a LINESTRING with a tolerance of 1000",
wkt = "LINESTRING(-122.306067 37.55412,-122.32328 37.561801,-122.325879 37.586852)",
expected = "LINESTRING (-122.30607 37.55412, -122.32588 37.58685)"
) { function.toleranceInput.value = 1000.0 }

testNullGeometryProcessing(
"Calling ST_Simplify on a NULL input"
)
}

override val function = STSimplify().apply {
binaryInput = NullableVarBinaryHolder()
toleranceInput = Float8Holder()
binaryOutput = NullableVarBinaryHolder()
buffer = allocateBuffer()
}

override val STSimplify.wkbInput: NullableVarBinaryHolder get() = function.binaryInput
override val STSimplify.wkbOutput: NullableVarBinaryHolder get() = function.binaryOutput
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ abstract class GeometryMeasurementFunSpec<F : SimpleFunction> : FunSpec() {
}
}

protected fun testNullGeometryMeasurement(
name: String,
wkt1: String? = null,
wkt2: String? = null,
wkt3: String? = null,
srid: Int,
) = test(name) {
function.apply {
wkt1?.also { wkbInput1.setFromWkt(wkt1, srid) }
wkt2?.also { wkbInput2.setFromWkt(wkt2, srid) }
wkt3?.also { wkbInput2.setFromWkt(wkt3, srid) }
setup()
eval()
measurementOutput.isNotSet()
}
}

protected abstract val F.wkbInput3: NullableVarBinaryHolder
}

Expand Down Expand Up @@ -121,6 +138,21 @@ abstract class GeometryMeasurementFunSpec<F : SimpleFunction> : FunSpec() {
}
}

protected fun testNullGeometryMeasurement(
name: String,
wkt1: String? = null,
wkt2: String? = null,
srid: Int,
) = test(name) {
function.apply {
wkt1?.also { wkbInput1.setFromWkt(wkt1, srid) }
wkt2?.also { wkbInput2.setFromWkt(wkt2, srid) }
setup()
eval()
measurementOutput.isNotSet()
}
}

protected abstract val F.wkbInput2: NullableVarBinaryHolder
}

Expand Down Expand Up @@ -163,4 +195,10 @@ abstract class GeometryMeasurementFunSpec<F : SimpleFunction> : FunSpec() {
isSet shouldBe 1
}
}

protected fun NullableFloat8Holder.isNotSet() {
run {
isSet shouldBe 0
}
}
}

0 comments on commit b70c8ef

Please sign in to comment.