@ -832,13 +832,12 @@ impl CondSelectGadget for Boolean {
}
}
#[ cfg(test) ]
mod test {
use super ::{ AllocatedBit , Boolean } ;
use crate ::{ prelude ::* , test_constraint_system ::TestConstraintSystem } ;
use algebra ::{ fields ::bls12_381 ::Fr , BitIterator , Field , PrimeField , UniformRand } ;
use num_traits ::{ One , Zero } ;
use r1cs_core ::ConstraintSystem ;
use rand ::SeedableRng ;
use rand_xorshift ::XorShiftRng ;
@ -903,8 +902,8 @@ mod test {
assert_eq ! ( c . value . unwrap ( ) , * a_val | * b_val ) ;
assert ! ( cs . is_satisfied ( ) ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
}
}
}
@ -920,14 +919,14 @@ mod test {
assert_eq ! ( c . value . unwrap ( ) , * a_val & * b_val ) ;
assert ! ( cs . is_satisfied ( ) ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! (
cs . get ( "and result" )
= = if * a_val & * b_val {
Field ::one ( )
Fr ::one ( )
} else {
Field ::zero ( )
Fr ::zero ( )
}
) ;
@ -935,9 +934,9 @@ mod test {
cs . set (
"and result" ,
if * a_val & * b_val {
Field ::zero ( )
Fr ::zero ( )
} else {
Field ::one ( )
Fr ::one ( )
} ,
) ;
assert ! ( ! cs . is_satisfied ( ) ) ;
@ -956,14 +955,14 @@ mod test {
assert_eq ! ( c . value . unwrap ( ) , * a_val & ! * b_val ) ;
assert ! ( cs . is_satisfied ( ) ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! (
cs . get ( "and not result" )
= = if * a_val & ! * b_val {
Field ::one ( )
Fr ::one ( )
} else {
Field ::zero ( )
Fr ::zero ( )
}
) ;
@ -971,9 +970,9 @@ mod test {
cs . set (
"and not result" ,
if * a_val & ! * b_val {
Field ::zero ( )
Fr ::zero ( )
} else {
Field ::one ( )
Fr ::one ( )
} ,
) ;
assert ! ( ! cs . is_satisfied ( ) ) ;
@ -992,14 +991,14 @@ mod test {
assert_eq ! ( c . value . unwrap ( ) , ! * a_val & ! * b_val ) ;
assert ! ( cs . is_satisfied ( ) ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Field ::one ( ) } else { Field ::zero ( ) } ) ;
assert ! ( cs . get ( "a/boolean" ) = = if * a_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! ( cs . get ( "b/boolean" ) = = if * b_val { Fr ::one ( ) } else { Fr ::zero ( ) } ) ;
assert ! (
cs . get ( "nor result" )
= = if ! * a_val & ! * b_val {
Field ::one ( )
Fr ::one ( )
} else {
Field ::zero ( )
Fr ::zero ( )
}
) ;
@ -1007,9 +1006,9 @@ mod test {
cs . set (
"nor result" ,
if ! * a_val & ! * b_val {
Field ::zero ( )
Fr ::zero ( )
} else {
Field ::one ( )
Fr ::one ( )
} ,
) ;
assert ! ( ! cs . is_satisfied ( ) ) ;
@ -1235,7 +1234,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1243,7 +1242,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1251,7 +1250,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1259,7 +1258,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
@ -1270,7 +1269,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1278,7 +1277,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1286,7 +1285,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1294,7 +1293,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
@ -1305,7 +1304,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1313,7 +1312,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1321,7 +1320,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1329,7 +1328,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
@ -1340,7 +1339,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1348,7 +1347,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Not ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1356,7 +1355,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1364,7 +1363,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "xor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "xor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
@ -1732,7 +1731,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "and result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1740,7 +1739,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1748,7 +1747,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1756,7 +1755,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
@ -1768,7 +1767,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1776,7 +1775,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1784,7 +1783,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1792,7 +1791,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
@ -1807,7 +1806,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1815,7 +1814,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1823,7 +1822,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "nor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "nor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1831,7 +1830,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "nor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "nor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
@ -1846,7 +1845,7 @@ mod test {
OperandType ::AllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,
(
@ -1854,7 +1853,7 @@ mod test {
OperandType ::AllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "and not result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "and not result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1862,7 +1861,7 @@ mod test {
OperandType ::NegatedAllocatedTrue ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "nor result" ) = = Field ::zero ( ) ) ;
assert ! ( cs . get ( "nor result" ) = = Fr ::zero ( ) ) ;
assert_eq ! ( v . value , Some ( false ) ) ;
} ,
(
@ -1870,7 +1869,7 @@ mod test {
OperandType ::NegatedAllocatedFalse ,
Boolean ::Is ( ref v ) ,
) = > {
assert ! ( cs . get ( "nor result" ) = = Field ::one ( ) ) ;
assert ! ( cs . get ( "nor result" ) = = Fr ::one ( ) ) ;
assert_eq ! ( v . value , Some ( true ) ) ;
} ,