Skip to content

Conversation

@Pygmalion69
Copy link
Owner

Summary

  • extend the distance calculator tests to cover the Point-based overload
  • add an antipodal scenario to validate cross-hemisphere calculations with tolerance
  • introduce a reflective helper to instantiate library Point objects for testing

Testing

  • ./gradlew test (fails: Failed to find Build Tools revision 35.0.0)

https://chatgpt.com/codex/tasks/task_e_68fa4af147e48327b324cb591467b88f

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 48 to 83
private fun createPoint(latitude: Double, longitude: Double): Point {
val constructor = Point::class.java.declaredConstructors.firstOrNull { ctor ->
val parameterTypes = ctor.parameterTypes
parameterTypes.size >= 2 &&
parameterTypes[0].isLatitudeLongitudeParameter() &&
parameterTypes[1].isLatitudeLongitudeParameter()
} ?: error("Unable to locate Point constructor with latitude/longitude parameters")

constructor.isAccessible = true

val parameterTypes = constructor.parameterTypes
val arguments = Array<Any?>(parameterTypes.size) { index ->
when (index) {
0 -> latitude
1 -> longitude
else -> parameterTypes[index].defaultValue()
}
}

return constructor.newInstance(*arguments) as Point
}

private fun Class<*>.isLatitudeLongitudeParameter(): Boolean {
return this == java.lang.Double.TYPE || this == java.lang.Double::class.java
}

private fun Class<*>.defaultValue(): Any? = when (this) {
java.lang.Double.TYPE -> 0.0
java.lang.Float.TYPE -> 0f
java.lang.Long.TYPE -> 0L
java.lang.Integer.TYPE -> 0
java.lang.Boolean.TYPE -> false
java.lang.Short.TYPE -> 0.toShort()
java.lang.Byte.TYPE -> 0.toByte()
java.lang.Character.TYPE -> 0.toChar()
else -> null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid constructing Point with nulls for non-null parameters

The reflective createPoint helper fills every constructor parameter after latitude/longitude with defaultValue() that returns null for reference types. io.ticofab.androidgpxparser.parser.domain.Point’s primary constructor includes non‑null parameters such as the extensions: List<Extension> argument which has a default value but is not nullable. Passing null through reflection triggers Kotlin’s parameter null checks and throws an IllegalArgumentException before the test reaches DistanceCalculator.distance, so the new test will reliably crash once the dependency is available. Construct Point using the public constructor with default arguments (e.g. Point(latitude, longitude) in Kotlin) or supply non‑null defaults for required parameters instead of null.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants