@@ -785,7 +785,7 @@ mod test {
785785 } ;
786786
787787 use powdr_ast:: analyzed:: Analyzed ;
788- use powdr_number:: { FieldElement , GoldilocksField , LargeInt } ;
788+ use powdr_number:: { BabyBearField , FieldElement , GoldilocksField , LargeInt } ;
789789
790790 use bit_vec:: BitVec ;
791791 use itertools:: Itertools ;
@@ -1061,4 +1061,36 @@ namespace arith(8);
10611061 & [ GoldilocksField :: from( 7 ) , GoldilocksField :: from( 0 ) ]
10621062 ) ;
10631063 }
1064+
1065+ #[ test]
1066+ fn add_sub_bb ( ) {
1067+ let pil = read_to_string ( "../test_data/pil/add_sub_bb.pil" ) . unwrap ( ) ;
1068+ let ( analyzed, fixed_col_vals) = read_pil :: < BabyBearField > ( & pil) ;
1069+ let fixed_data = FixedData :: new ( & analyzed, & fixed_col_vals, & [ ] , Default :: default ( ) , 0 ) ;
1070+ let fixed_data = global_constraints:: set_global_constraints ( fixed_data) ;
1071+
1072+ // First try to compute the "gt" flag.
1073+ let interpreter_gt =
1074+ TestInterpreter :: new ( & analyzed, & fixed_data, "main_add_sub" , 4 , 1 , & |_| {
1075+ Err ( "Query not implemented" . to_string ( ) )
1076+ } ) ;
1077+ interpreter_gt. test ( & [ 1 , 2 , 3 , 4 , 0 ] , & [ 1 , 2 , 3 , 4 , 1 ] ) ;
1078+ interpreter_gt. test ( & [ 3 , 0 , 2 , 4 , 0 ] , & [ 3 , 0 , 2 , 4 , 0 ] ) ;
1079+ interpreter_gt. test ( & [ 5 , 2 , 0 , 4 , 0 ] , & [ 5 , 2 , 0 , 4 , 0 ] ) ;
1080+
1081+ // Then check that it also works if the result is already provided.
1082+ let interpreter_gt =
1083+ TestInterpreter :: new ( & analyzed, & fixed_data, "main_add_sub" , 5 , 0 , & |_| {
1084+ Err ( "Query not implemented" . to_string ( ) )
1085+ } ) ;
1086+ interpreter_gt. test ( & [ 1 , 2 , 3 , 4 , 1 ] , & [ 1 , 2 , 3 , 4 , 1 ] ) ;
1087+ interpreter_gt. test ( & [ 3 , 0 , 2 , 4 , 0 ] , & [ 3 , 0 , 2 , 4 , 0 ] ) ;
1088+ interpreter_gt. test ( & [ 5 , 2 , 0 , 4 , 0 ] , & [ 5 , 2 , 0 , 4 , 0 ] ) ;
1089+
1090+ // This should actually panic, but it does not, because
1091+ // A_h is assigned a value outside of the two-byte range.
1092+ // We do not detect this because lookups that only result
1093+ // in range constraints are removed.
1094+ interpreter_gt. test ( & [ 1 , 2 , 3 , 4 , 0 ] , & [ 1 , 2 , 3 , 4 , 0 ] ) ;
1095+ }
10641096}
0 commit comments