ark-r1cs-std/src/boolean/test_utils.rs
src/boolean/test_utils.rsRaw
1use crate::test_utils;
2
3use super::*;
4use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
5
6pub(crate) fn test_unary_op<F: Field>(
7 a: bool,
8 mode: AllocationMode,
9 test: impl FnOnce(Boolean<F>) -> Result<(), SynthesisError>,
10) -> Result<(), SynthesisError> {
11 let cs = ConstraintSystem::<F>::new_ref();
12 let a = Boolean::<F>::new_variable(cs.clone(), || Ok(a), mode)?;
13 test(a)
14}
15
16pub(crate) fn test_binary_op<F: Field>(
17 a: bool,
18 b: bool,
19 mode_a: AllocationMode,
20 mode_b: AllocationMode,
21 test: impl FnOnce(Boolean<F>, Boolean<F>) -> Result<(), SynthesisError>,
22) -> Result<(), SynthesisError> {
23 let cs = ConstraintSystem::<F>::new_ref();
24 let a = Boolean::<F>::new_variable(cs.clone(), || Ok(a), mode_a)?;
25 let b = Boolean::<F>::new_variable(cs.clone(), || Ok(b), mode_b)?;
26 test(a, b)
27}
28
29pub(crate) fn run_binary_exhaustive<F: Field>(
30 test: impl Fn(Boolean<F>, Boolean<F>) -> Result<(), SynthesisError> + Copy,
31) -> Result<(), SynthesisError> {
32 for (mode_a, a) in test_utils::combination([false, true].into_iter()) {
33 for (mode_b, b) in test_utils::combination([false, true].into_iter()) {
34 test_binary_op(a, b, mode_a, mode_b, test)?;
35 }
36 }
37 Ok(())
38}
39
40pub(crate) fn run_unary_exhaustive<F: Field>(
41 test: impl Fn(Boolean<F>) -> Result<(), SynthesisError> + Copy,
42) -> Result<(), SynthesisError> {
43 for (mode, a) in test_utils::combination([false, true].into_iter()) {
44 test_unary_op(a, mode, test)?;
45 }
46 Ok(())
47}