Skip to content

Expand test suite - #46

Merged
dhardy merged 20 commits into
masterfrom
copilot/build-comprehensive-test-suite
Jul 15, 2026
Merged

Expand test suite#46
dhardy merged 20 commits into
masterfrom
copilot/build-comprehensive-test-suite

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Cleans up the test suite per scope constraints: no src changes, no cast-mirrors-conv tautology tests, minimal array/tuple coverage, use std consts where appropriate.

Changes

  • Remove tests/common/mod.rs — drop assert_ok_eq, assert_range, assert_inexact wrappers; use assert_eq! with Ok(...) / Err(Error::Range) / Err(Error::Inexact) directly
  • Remove cast_approx_mirrors_conv_approx test from conv_approx.rs — testing that cast mirrors conv is a tautology since Cast is a blanket impl over Conv
  • Improve float_approx.rs — replace raw bit-pattern construction with std consts:
    • f64::MIN_POSITIVE / 2.0 for subnormal, (f32::MIN_POSITIVE as f64) / 2.0 for small-normal
    • Derive negatives with unary - instead of bit manipulation
    • Inline single-use result variables (positive_zero, etc.)
    • Remove unnecessary parentheses: (1151u64) << 521151u64 << 52
  • Revert src/impl_float.rs to master — a prior commit restructured the if/else if in ConvApprox<f64> for f32; reverted without touching anything else

Before / After (representative)

// Before
assert_ok_eq(i8::try_conv_trunc(f32::from(i8::MIN)), i8::MIN);
assert_range(i8::try_conv_trunc(f32::from(i8::MAX) + 1.0));

// After
assert_eq!(i8::try_conv_trunc(f32::from(i8::MIN)), Ok(i8::MIN));
assert_eq!(i8::try_conv_trunc(f32::from(i8::MAX) + 1.0), Err(Error::Range));

@dhardy dhardy changed the title Refactor test suite: remove common helpers, use assert_eq! directly Expand test suite Jul 15, 2026
@dhardy

dhardy commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

So the purpose of this was to address (or at least chip away at) the last limitation listed in the readme:

You want a thoroughly tested library (we're not quite there yet)

This work is rather sloppy (over-zealously checking some parts of the API surface while still only checking a small number of actual conversions), but it did find something at least: impl ConvApprox<f64> for f32 doesn't handle small (normal) f64 values which could be converted to sub-normal f32 values.

I considered writing a test suite using proptest. The main issue I see is that the bounds used in the tests would need much of the same code as the conversions use, making the test suite prone to the same bugs it is trying to catch.

(Also: should ConvApprox<f64> for f32 convert f64::NAN to f32::NAN or continue to return Error::Range? The fact that Conv<f32> for f64 is derived from From and does convert NAN makes this incongruous. And should too large f64 values convert to f32::INFINITY or result in a range error?)

@dhardy dhardy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Notes for myself.

These tests are simultaneously repetitive, inexhaustive and inconsistent in style. And mostly cover trivial stuff. But with a few tweaks they have some value.

Comment thread tests/conv_approx.rs Outdated
Comment thread tests/conv_approx.rs
Comment thread tests/core_ops_types.rs Outdated
Comment thread tests/float_approx.rs Outdated
Comment thread tests/float_conv.rs Outdated
Comment thread tests/float_conv.rs Outdated
Comment thread tests/int_to_float.rs
Comment thread tests/tuple_conv.rs Outdated
@dhardy
dhardy marked this pull request as ready for review July 15, 2026 16:13
@dhardy
dhardy merged commit 11d4d6b into master Jul 15, 2026
4 checks passed
@dhardy dhardy mentioned this pull request Jul 16, 2026
@dhardy
dhardy deleted the copilot/build-comprehensive-test-suite branch July 16, 2026 11:18
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