Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Nov 4, 2024
1 parent b6b35bd commit b658b7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions tabled/src/settings/object/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ pub struct StepByObjectIter<I> {

impl<I> StepByObjectIter<I> {
fn new(iter: I, step: usize) -> Self {
Self {
iter,
step,
end: false,
}
let end = step == 0;

Self { iter, step, end }
}
}

Expand All @@ -155,7 +153,7 @@ where
let item = self.iter.next();
let _ = item.as_ref()?;

for _ in 0..self.step {
for _ in 0..self.step - 1 {
let next = self.iter.next();
if next.is_none() {
self.end = true;
Expand Down Expand Up @@ -257,22 +255,30 @@ mod tests {
assert_eq!(cells((1, 5).skip(1), 10, 10), []);
assert_eq!(cells((1, 5).skip(0), 10, 10), [Cell(1, 5)]);

assert_eq!(cells(Rows::new(1..5).skip(00), 10, 10), []);
assert_eq!(
cells(Rows::new(1..5).skip(0), 10, 10),
[Row(1), Row(2), Row(3), Row(4)]
);
}

#[test]
fn test_step_by_iterator() {
use Entity::*;

assert_eq!(cells(Rows::new(1..5).step_by(1), 10, 10), [Row(1), Row(3)]);
assert_eq!(cells(Rows::new(1..5).step_by(0), 10, 10), []);
assert_eq!(
cells(Rows::new(1..5).step_by(1), 10, 10),
[Row(1), Row(2), Row(3), Row(4)]
);
assert_eq!(cells(Rows::new(1..5).step_by(2), 10, 10), [Row(1), Row(3)]);

assert_eq!(
cells(Columns::new(5..).step_by(0), 10, 10),
cells(Columns::new(5..).step_by(1), 10, 10),
[Column(5), Column(6), Column(7), Column(8), Column(9)]
);

assert_eq!(cells((1, 5).step_by(2), 10, 10), [Cell(1, 5)]);
assert_eq!(cells((1, 5).step_by(1), 10, 10), [Cell(1, 5)]);
assert_eq!(cells((1, 5).step_by(0), 10, 10), [Cell(1, 5)]);

assert_eq!(cells(Rows::new(1..5).step_by(100), 10, 10), [Row(1)]);
}
Expand Down
2 changes: 1 addition & 1 deletion tabled/tests/settings/object_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_table!(

test_table!(
step_by,
Matrix::new(3, 3).with(Style::psql()).modify(Columns::new(..).step_by(2), Alignment::right()),
Matrix::new(3, 3).with(Style::psql()).modify(Columns::new(..).step_by(3), Alignment::right()),
" N | column 0 | column 1 | column 2 "
"---+----------+----------+----------"
" 0 | 0-0 | 0-1 | 0-2 "
Expand Down

0 comments on commit b658b7f

Please sign in to comment.