-
Notifications
You must be signed in to change notification settings - Fork 13
Add antipodal point unit test for distance calculator #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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".
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68fa4af147e48327b324cb591467b88f