Skip to content

Commit

Permalink
Merge pull request #55 from availproject/marko/expand-cell-struct
Browse files Browse the repository at this point in the history
Added get_dimensions helper function to Cell
  • Loading branch information
markopoloparadox authored Jan 15, 2024
2 parents 8f58e5f + dfd2e82 commit 3050172
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 @@ -56,6 +56,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 63 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 @@ -1257,4 +1273,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_row = usize::try_from(row).unwrap();
let expected_col = usize::try_from(col).unwrap();
let (actual_row, actual_col) = cell.get_dimensions().unwrap();
assert_eq!(actual_row, expected_row);
assert_eq!(actual_col, expected_col);
}
}

0 comments on commit 3050172

Please sign in to comment.