@@ -103,10 +103,10 @@ mod tests {
103
103
// Get input value as a u64
104
104
let lo: u32 = stack. pop ( ) . unwrap ( ) . try_into ( ) . unwrap ( ) ;
105
105
let hi: u32 = stack. pop ( ) . unwrap ( ) . try_into ( ) . unwrap ( ) ;
106
- let value_u64 : u64 = lo as u64 + ( 1 << 32 ) * ( hi as u64 ) ;
106
+ let value = u64 :: from ( lo ) + ( 1 << 32 ) * u64 :: from ( hi) ;
107
107
108
- let log_2_floor = value_u64 . ilog2 ( ) as u64 ;
109
- stack. push ( BFieldElement :: new ( log_2_floor) ) ;
108
+ let log_2_floor = value . ilog2 ( ) ;
109
+ stack. push ( bfe ! ( log_2_floor) ) ;
110
110
}
111
111
112
112
fn pseudorandom_initial_state (
@@ -115,7 +115,7 @@ mod tests {
115
115
bench_case : Option < crate :: snippet_bencher:: BenchmarkCase > ,
116
116
) -> Vec < BFieldElement > {
117
117
match bench_case {
118
- Some ( BenchmarkCase :: CommonCase ) => self . init_state ( u32:: MAX as u64 ) ,
118
+ Some ( BenchmarkCase :: CommonCase ) => self . init_state ( u64 :: from ( u32:: MAX ) ) ,
119
119
Some ( BenchmarkCase :: WorstCase ) => self . init_state ( u64:: MAX ) ,
120
120
None => {
121
121
let mut rng: StdRng = SeedableRng :: from_seed ( seed) ;
@@ -141,47 +141,53 @@ mod tests {
141
141
142
142
#[ test]
143
143
fn lo_is_not_u32_hi_is_zero ( ) {
144
- let not_u32 = BFieldElement :: new ( u32:: MAX as u64 + 1 ) ;
144
+ let not_u32 = bfe ! ( u64 :: from ( u32 :: MAX ) + 1 ) ;
145
145
let mut init_stack = Log2FloorU64 . init_stack_for_isolated_run ( ) ;
146
- init_stack. push ( BFieldElement :: new ( 0 ) ) ;
146
+ init_stack. push ( bfe ! ( 0 ) ) ;
147
147
init_stack. push ( not_u32) ;
148
148
149
149
let init_state = InitVmState :: with_stack ( init_stack) ;
150
+ let expected_err =
151
+ InstructionError :: OpStackError ( OpStackError :: FailedU32Conversion ( not_u32) ) ;
150
152
negative_test (
151
153
& ShadowedClosure :: new ( Log2FloorU64 ) ,
152
154
init_state,
153
- & [ InstructionError :: FailedU32Conversion ( not_u32 ) ] ,
155
+ & [ expected_err ] ,
154
156
) ;
155
157
}
156
158
157
159
#[ test]
158
160
fn hi_is_not_u32 ( ) {
159
- let not_u32 = BFieldElement :: new ( u32:: MAX as u64 + 1 ) ;
161
+ let not_u32 = bfe ! ( u64 :: from ( u32 :: MAX ) + 1 ) ;
160
162
let mut init_stack = Log2FloorU64 . init_stack_for_isolated_run ( ) ;
161
163
init_stack. push ( not_u32) ;
162
- init_stack. push ( BFieldElement :: new ( 16 ) ) ;
164
+ init_stack. push ( bfe ! ( 16 ) ) ;
163
165
164
166
let init_state = InitVmState :: with_stack ( init_stack) ;
167
+ let expected_err =
168
+ InstructionError :: OpStackError ( OpStackError :: FailedU32Conversion ( not_u32) ) ;
165
169
negative_test (
166
170
& ShadowedClosure :: new ( Log2FloorU64 ) ,
167
171
init_state,
168
- & [ InstructionError :: FailedU32Conversion ( not_u32 ) ] ,
172
+ & [ expected_err ] ,
169
173
) ;
170
174
}
171
175
172
176
#[ test]
173
177
fn hi_is_not_u32_alt ( ) {
174
- let n: u64 = rand:: thread_rng ( ) . next_u32 ( ) as u64 ;
175
- let not_u32 = BFieldElement :: new ( u32:: MAX as u64 + 1 + n) ;
178
+ let n = u64 :: from ( rand:: thread_rng ( ) . next_u32 ( ) ) ;
179
+ let not_u32 = bfe ! ( u64 :: from ( u32 :: MAX ) + 1 + n) ;
176
180
let mut init_stack = Log2FloorU64 . init_stack_for_isolated_run ( ) ;
177
181
init_stack. push ( not_u32) ;
178
- init_stack. push ( BFieldElement :: new ( 16 ) ) ;
182
+ init_stack. push ( bfe ! ( 16 ) ) ;
179
183
180
184
let init_state = InitVmState :: with_stack ( init_stack) ;
185
+ let expected_err =
186
+ InstructionError :: OpStackError ( OpStackError :: FailedU32Conversion ( not_u32) ) ;
181
187
negative_test (
182
188
& ShadowedClosure :: new ( Log2FloorU64 ) ,
183
189
init_state,
184
- & [ InstructionError :: FailedU32Conversion ( not_u32 ) ] ,
190
+ & [ expected_err ] ,
185
191
) ;
186
192
}
187
193
0 commit comments