Skip to content

Commit

Permalink
feat(test): add unit tests for *_to_num
Browse files Browse the repository at this point in the history
  • Loading branch information
shuklaayush committed Nov 25, 2023
1 parent d4deed7 commit 5cda44b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions halo2-base/src/gates/tests/flex_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ pub fn test_num_to_bits(num: usize, bits: usize) -> Vec<Fr> {
})
}

#[test_case([0,1,1].map(Fr::from).to_vec() => Fr::from(6); "bits_to_num(): [0,1,1]")]
pub fn test_bits_to_num(bits: Vec<Fr>) -> Fr {
base_test().run_gate(|ctx, chip| {
let bits = ctx.assign_witnesses(bits);
*chip.bits_to_num(ctx, bits.as_slice()).value()
})
}

#[test_case(Fr::from(3), BigUint::from(3u32), 4 => Fr::from(27); "pow_var(): 3^3 = 27")]
pub fn test_pow_var(a: Fr, exp: BigUint, max_bits: usize) -> Fr {
assert!(exp.bits() <= max_bits as u64);
Expand Down
8 changes: 8 additions & 0 deletions halo2-base/src/gates/tests/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ pub fn test_decompose_le(num: Fr, limb_bits: usize, num_limbs: usize) -> Vec<Fr>
chip.decompose_le(ctx, num, limb_bits, num_limbs).iter().map(|x| *x.value()).collect()
})
}

#[test_case([0x4, 0x3, 0x2, 0x1].map(Fr::from).to_vec(), 4 => Fr::from(0x1234); "limbs_to_num([0x4, 0x3, 0x2, 0x1], 4)")]
pub fn test_limbs_to_num(limbs: Vec<Fr>, limb_bits: usize) -> Fr {
base_test().run(|ctx, chip| {
let limbs = ctx.assign_witnesses(limbs);
*chip.limbs_to_num(ctx, limbs.as_slice(), limb_bits).value()
})
}

0 comments on commit 5cda44b

Please sign in to comment.