Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/std/coord_arith/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl core::ops::Sub<RowOffset> for RowIndex {
#[inline]
fn sub(self, rhs: RowOffset) -> Self::Output {
let lhs = *self;
let rhs = (*rhs).try_into().ok()?;
Some(Self::new(lhs.checked_sub(rhs)?))
let rhs = *rhs;
Some(Self::new(lhs.checked_sub_signed(rhs)?))
}
}

Expand Down Expand Up @@ -59,8 +59,8 @@ impl core::ops::Sub<ColOffset> for ColIndex {
#[inline]
fn sub(self, rhs: ColOffset) -> Self::Output {
let lhs = *self;
let rhs = (*rhs).try_into().ok()?;
Some(Self::new(lhs.checked_sub(rhs)?))
let rhs = *rhs;
Some(Self::new(lhs.checked_sub_signed(rhs)?))
}
}

Expand Down
45 changes: 34 additions & 11 deletions src/std/coord_arith/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,32 @@ where
let thr: usize = isize::MAX.try_into().unwrap();
let tests = [
//
((0, -2_isize), None),
((0, -1), None),
((0, isize::MIN), Some(thr + 1)),
((0, isize::MIN + 1), Some(thr)),
((0, (isize::MIN + 2)), Some(thr - 1)),
((0, -2_isize), Some(2)),
((0, -1), Some(1)),
((0, 0), Some(0_usize)),
((0, 1), None),
((0, 2), None),
//
((1, -2), None),
((1, -1), None),
((1, isize::MIN), Some(thr + 2)),
((1, isize::MIN + 1), Some(thr + 1)),
((1, (isize::MIN + 2)), Some(thr)),
((1, (isize::MIN + 3)), Some(thr - 1)),
((1, -2), Some(3)),
((1, -1), Some(2)),
((1, 0), Some(1)),
((1, 1), Some(0)),
((1, 2), None),
((1, 3), None),
//
((thr - 1, -2), None),
((thr - 1, -1), None),
((thr - 1, isize::MIN), Some(2 * thr)),
((thr - 1, isize::MIN + 1), Some(2 * thr - 1)),
((thr - 1, (isize::MIN + 2)), Some(2 * thr - 2)),
((thr - 1, (isize::MIN + 3)), Some(2 * thr - 3)),
((thr - 1, -2), Some(thr + 1)),
((thr - 1, -1), Some(thr)),
((thr - 1, 0), Some(thr - 1)),
((thr - 1, 1), Some(thr - 2)),
((thr - 1, 2), Some(thr - 3)),
Expand All @@ -192,8 +203,12 @@ where
((thr - 1, isize::MAX - 1), Some(0)),
((thr - 1, isize::MAX), None),
//
((thr, -2), None),
((thr, -1), None),
((thr, isize::MIN), Some(2 * thr + 1)),
((thr, isize::MIN + 1), Some(2 * thr)),
((thr, (isize::MIN + 2)), Some(2 * thr - 1)),
((thr, (isize::MIN + 3)), Some(2 * thr - 2)),
((thr, -2), Some(thr + 2)),
((thr, -1), Some(thr + 1)),
((thr, 0), Some(thr)),
((thr, 1), Some(thr - 1)),
((thr, 2), Some(thr - 2)),
Expand All @@ -202,8 +217,12 @@ where
((thr, isize::MAX - 1), Some(1)),
((thr, isize::MAX), Some(0)),
//
((thr + 1, -2), None),
((thr + 1, -1), None),
((thr + 1, isize::MIN), None),
((thr + 1, isize::MIN + 1), Some(2 * thr + 1)),
((thr + 1, (isize::MIN + 2)), Some(2 * thr)),
((thr + 1, (isize::MIN + 3)), Some(2 * thr - 1)),
((thr + 1, -2), Some(thr + 3)),
((thr + 1, -1), Some(thr + 2)),
((thr + 1, 0), Some(thr + 1)),
((thr + 1, 1), Some(thr)),
((thr + 1, 2), Some(thr - 1)),
Expand All @@ -220,7 +239,11 @@ where
#[test]
fn rowindex_offset_test() {
enumerate_offset_tests(|(a, b), c| {
assert_eq!(RowIndex::new(a) - RowOffset::new(b), c.map(RowIndex::new));
assert_eq!(
RowIndex::new(a) - RowOffset::new(b),
c.map(RowIndex::new),
"{a} - {b}",
);
});
}

Expand Down
Loading