Skip to content

Commit

Permalink
Added get_dimensions helper function to Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Oct 17, 2023
1 parent d871bed commit 69bc8fd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions kate/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ pub struct Cell {
pub col: BlockLengthColumns,
}

impl Cell {
// Returns usize versions of row and col.
// If an error is returned it means that we weren't able to
// convert an u32 value to usize.
pub fn get_dimensions(&self) -> Result<(usize, usize), ()> {

Check warning on line 62 in kate/src/com.rs

View workflow job for this annotation

GitHub Actions / build_and_test

this returns a `Result<_, ()>`
let Ok(row) = usize::try_from(self.row.0) else {
return Err(());
};
let Ok(col) = usize::try_from(self.col.0) else {
return Err(());
};

Ok((row, col))
}
}

#[derive(Error, Debug)]
pub enum Error {
PlonkError(#[from] PlonkError),
Expand Down Expand Up @@ -1207,4 +1223,20 @@ Let's see how this gets encoded and then reconstructed by sampling only some dat
fn serde_block_length_types_untagged(data: &str) -> Cell {
serde_json::from_str(data).unwrap()
}

#[test]
fn cell_get_dimensions_returns_the_correct_values() {
let row = 20;
let col = 25;
let cell = Cell {
row: BlockLengthRows::new(row),
col: BlockLengthColumns::new(col),
};

let expected_rows = usize::try_from(row).unwrap();
let expected_cols = usize::try_from(col).unwrap();
let (actual_row, actual_col) = cell.get_dimensions().unwrap();
assert_eq!(actual_row, expected_rows);
assert_eq!(actual_col, expected_cols);
}
}

0 comments on commit 69bc8fd

Please sign in to comment.