feat: Add more tests to b2p edge cases

This commit is contained in:
0xalivecow 2024-11-02 14:18:10 +01:00
parent 8db0bbaa63
commit 26ca12b419
No known key found for this signature in database
2 changed files with 64 additions and 18 deletions

View file

@ -51,4 +51,46 @@ mod tests {
Ok(()) Ok(())
} }
#[test]
fn block2poly_task03() -> Result<()> {
let block: Value = json!({"block" : "AAAAAAAAAAAAAAAAAAAAAA==", "semantic" : "gcm"});
let coefficients: Vec<u8> = vec![];
assert_eq!(
block2poly(&block)?,
coefficients,
"Coefficients were: {:?}",
block2poly(&block)?
);
Ok(())
}
#[test]
fn block2poly_task04() -> Result<()> {
let block: Value = json!({"block" : "", "semantic" : "gcm"});
let coefficients: Vec<u8> = vec![];
assert_eq!(
block2poly(&block)?,
coefficients,
"Coefficients were: {:?}",
block2poly(&block)?
);
Ok(())
}
#[test]
fn block2poly_task_empty_xex() -> Result<()> {
let block: Value = json!({"block" : "", "semantic" : "xex"});
let coefficients: Vec<u8> = vec![];
assert_eq!(
block2poly(&block)?,
coefficients,
"Coefficients were: {:?}",
block2poly(&block)?
);
Ok(())
}
} }

View file

@ -104,6 +104,9 @@ pub fn get_bit_indices_from_byte(byte: u8) -> Vec<u8> {
} }
pub fn block_2_polynomial(block: Vec<u8>, semantic: &str) -> Result<Vec<u8>> { pub fn block_2_polynomial(block: Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
if block.len() == 0 {
Ok(Vec::new())
} else {
let mut output: Vec<u8> = vec![]; let mut output: Vec<u8> = vec![];
match semantic { match semantic {
"xex" => { "xex" => {
@ -130,6 +133,7 @@ pub fn block_2_polynomial(block: Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
} }
_ => Err(anyhow!("Error in b2p")), _ => Err(anyhow!("Error in b2p")),
} }
}
} }
pub fn polynomial_2_block(coefficients: Vec<u8>, semantic: &str) -> Result<Vec<u8>> { pub fn polynomial_2_block(coefficients: Vec<u8>, semantic: &str) -> Result<Vec<u8>> {