Skip to content

test(curves): pin LUT inspection, custom-clone, and Bezier edges#515

Draft
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/improve-code-coverage-xaNsj-curves
Draft

test(curves): pin LUT inspection, custom-clone, and Bezier edges#515
EffortlessSteven wants to merge 1 commit into
mainfrom
claude/improve-code-coverage-xaNsj-curves

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Adds 17 new tests for openracing-curves and removes one trivial dead expression.

What changed in src

curve_type.rsevaluate for Logarithmic had (value.ln() / log_base) / 1.0. The companion to_lut arm already drops the / 1.0. Trailing / 1.0 removed; no semantic change. Verified by evaluate_matches_to_lut_endpoints.

What the new tests cover

  • LUT inspection on non-monotonic data. min_value / max_value on a tent-function LUT; is_monotonic for strictly-decreasing and constant LUTs (the latter pins the < non-decreasing boundary).
  • CurveLut::table() returns all 256 entries with the expected linear endpoints.
  • Bezier evaluate clamps t. Below 0 matches evaluate(0.0); above 1 matches evaluate(1.0).
  • Bezier map with coincident-x control points. The Newton-Raphson early-out branch (dx_dt.abs() < EPSILON) is now exercised; output stays finite and in [0, 1].
  • CurveType::Custom(...).to_lut() clones the inner LUT under PartialEq equality.
  • CurveType::Custom(...).evaluate(_) clamps out-of-range input to endpoint LUT values.
  • CurveError::PartialEq for matching + differing field cases and cross-variant inequality.
  • CurveLut Deserialize rejects payloads with != 256 entries (both too-small and too-large checked).
  • logarithmic short-circuits to exact 0.0 and 1.0 at the endpoints (strict equality, not tolerance), and matches to_lut().lookup(_) at the endpoints.
  • BezierCurve Clone / Debug visibly exercised.
  • CurveLut::lookup(1.0) reaches table[255] (high-grid clamp path).

Smells noticed but not addressed in this PR

  • CurveLut::Deserialize does not validate NaN/Inf entries — accepted as-is, which can later produce non-finite output through lookup and break RT-safety claims for downstream consumers. Architecturally significant; happy to follow up with a validation PR if you want a strict-finite policy.
  • BezierCurve::map Newton-Raphson with dx_dt ≈ 0 at iteration 0 breaks immediately and returns the seed t = target_x without converging. The new coincident-x test confirms map stays in range and doesn't panic; closing the convergence gap would need a different root-finder (bisection fallback). Architecturally significant; not included here.

Verification

cargo test -p openracing-curves
running 17/45/14/11/34/4/11/11 → 147 tests pass
cargo clippy -p openracing-curves --tests -- -D warnings    # clean

Test plan

  • cargo test -p openracing-curves
  • cargo clippy -p openracing-curves --tests -- -D warnings
  • Coverage CI confirms a bump for the crate

https://claude.ai/code/session_01NZ5jzdE2H3bbuPuYqbjCnh


Generated by Claude Code

Adds 17 tests for `openracing-curves` covering paths the existing
suite did not pin down, and removes a redundant `/ 1.0` operation
in the logarithmic `evaluate` short-circuit (no semantic change,
the equivalent `to_lut` arm already omits it).

The new tests:

- `CurveLut::min_value` / `max_value` on a non-monotonic (tent
  function) LUT, plus `is_monotonic` for strictly-decreasing and
  constant LUTs — the latter covers the `<` (non-decreasing)
  boundary in the existing implementation.
- `CurveLut::table()` returns 256 entries with `[0]=0`, `[255]=1`
  for the linear LUT.
- `BezierCurve::evaluate(t)` clamps `t < 0` and `t > 1` (regression
  guard: drop the clamp and the test breaks).
- `BezierCurve::map` does not diverge when two interior control
  points share an `x` coordinate (the Newton-Raphson's
  `dx_dt.abs() < EPSILON` early-out is now exercised), and produces
  a finite output in `[0, 1]`.
- `CurveType::Custom(...)::to_lut` clones the inner LUT (asserted
  via `PartialEq`).
- `CurveType::Custom(...)::evaluate` clamps input below `0.0` and
  above `1.0` to the endpoint LUT values.
- `CurveError::PartialEq` for both matching and differing field
  cases, including cross-variant inequality.
- `CurveLut` `Deserialize` rejects payloads with too few or too
  many entries (256 only).
- `CurveType::logarithmic(_)?.evaluate(0.0) == 0.0` and
  `evaluate(1.0) == 1.0` under strict equality (exercises the
  short-circuit branches).
- `evaluate` matches `to_lut().lookup(_)` at the endpoints.
- `BezierCurve` `Clone` / `Debug` visibly exercised.
- `CurveLut::lookup(1.0)` reaches `table[255]` (high-grid clamp).

Verified with `cargo test -p openracing-curves` (147 tests pass)
and `cargo clippy -p openracing-curves --tests -- -D warnings`.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minute and 9 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37184ecb-2b1c-444a-9394-298bccc9f8f5

📥 Commits

Reviewing files that changed from the base of the PR and between e6185be and 836e70f.

📒 Files selected for processing (2)
  • crates/openracing-curves/src/curve_type.rs
  • crates/openracing-curves/tests/coverage_gaps.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/improve-code-coverage-xaNsj-curves

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

Compatibility Layer Usage Report

Current usage count: 193
Baseline usage count: 193
ℹ️ Usage unchanged

📈 Usage Trend (Last 30 Days)

  • Peak usage: 193
  • Current trend: insufficient_data (0%)
  • Projected removal: unknown

Usage Details

  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/compat_impl.rs:69 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/linux.rs:1253 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/linux.rs:1282 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/hid/mod.rs:230 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:290 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:742 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/engine/src/protocol.rs:749 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/service_example.rs:189 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/service_example.rs:218 - temp_c
  • /home/runner/work/OpenRacing/OpenRacing/crates/schemas/src/integration_test.rs:79 - temp_c

... and 183 more occurrences

Migration Guide

To migrate these usages, replace:

  • .temp_c().temperature_c
  • .faults().fault_flags
  • .wheel_angle_mdeg().wheel_angle_deg
  • .wheel_speed_mrad_s().wheel_speed_rad_s

See Migration Patterns for detailed examples.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants