danlehmann / arbitrary-int

A modern and lightweight implementation of arbitrary integers for Rust
MIT License
32 stars 13 forks source link

Implement `core::fmt::Step` for `UInt` #30

Closed pickx closed 1 year ago

pickx commented 1 year ago

Closes #29.

danlehmann commented 1 year ago

This looks great, thanks a lot for the contribution.

  1. We should have tests to ensure both the arbitrary int overflowing as well as the underlying type overflowing. I wrote them up (and they pass just fine):
#[cfg(feature = "step_trait")]
#[test]
fn forward_out_of_range() {
    // In range
    assert_eq!(Some(u7::new(121)), Step::forward_checked(u7::new(120), 1));
    assert_eq!(Some(u7::new(127)), Step::forward_checked(u7::new(120), 7));

    // Out of range
    assert_eq!(None, Step::forward_checked(u7::new(120), 8));

    // Out of range for the underlying type
    assert_eq!(None, Step::forward_checked(u7::new(120), 140));
}

#[cfg(feature = "step_trait")]
#[test]
fn backward_out_of_range() {
    // In range
    assert_eq!(Some(u7::new(1)), Step::backward_checked(u7::new(10), 9));
    assert_eq!(Some(u7::new(0)), Step::backward_checked(u7::new(10), 10));

    // Out of range
    assert_eq!(None, Step::backward_checked(u7::new(10), 11));
}
danlehmann commented 1 year ago
  1. Github's test runner won't currently test this, as the feature needs to be enabled. We can add that:

In .github/workflows, make a copy of test-const.yml and swap out the feature.

Once that is added and uploaded, Github should automatically run the test suite with this feature enabled.

danlehmann commented 1 year ago

Oh! And:

  1. Add the new feature to the CHANGELOG.md, putting it under a new section 1.2.7
pickx commented 1 year ago

thanks for the guidance! please let me know if there's anything else I'm missing

danlehmann commented 1 year ago

Thanks a lot for your contribution!