feat: Add more tests to b2p edge cases
This commit is contained in:
parent
8db0bbaa63
commit
26ca12b419
2 changed files with 64 additions and 18 deletions
|
|
@ -51,4 +51,46 @@ mod tests {
|
|||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,31 +104,35 @@ pub fn get_bit_indices_from_byte(byte: u8) -> Vec<u8> {
|
|||
}
|
||||
|
||||
pub fn block_2_polynomial(block: Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
||||
let mut output: Vec<u8> = vec![];
|
||||
match semantic {
|
||||
"xex" => {
|
||||
for i in 0u8..=15 {
|
||||
for j in 0u8..=7 {
|
||||
if (block[i as usize] >> j) & 1 == 1 {
|
||||
output.push(8 * i + j);
|
||||
if block.len() == 0 {
|
||||
Ok(Vec::new())
|
||||
} else {
|
||||
let mut output: Vec<u8> = vec![];
|
||||
match semantic {
|
||||
"xex" => {
|
||||
for i in 0u8..=15 {
|
||||
for j in 0u8..=7 {
|
||||
if (block[i as usize] >> j) & 1 == 1 {
|
||||
output.push(8 * i + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
output.sort();
|
||||
Ok(output)
|
||||
}
|
||||
output.sort();
|
||||
Ok(output)
|
||||
}
|
||||
"gcm" => {
|
||||
for i in 0u8..=15 {
|
||||
for j in 0u8..=7 {
|
||||
if (block[i as usize] >> j) & 1 == 1 {
|
||||
output.push(8 * i + 7 - j);
|
||||
"gcm" => {
|
||||
for i in 0u8..=15 {
|
||||
for j in 0u8..=7 {
|
||||
if (block[i as usize] >> j) & 1 == 1 {
|
||||
output.push(8 * i + 7 - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
output.sort();
|
||||
Ok(output)
|
||||
}
|
||||
output.sort();
|
||||
Ok(output)
|
||||
_ => Err(anyhow!("Error in b2p")),
|
||||
}
|
||||
_ => Err(anyhow!("Error in b2p")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue