Skip to content

Commit

Permalink
test: add tests for i32 checked_shr intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Nov 17, 2023
1 parent a942323 commit 491ec6b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions codegen/masm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,4 +756,31 @@ proptest! {
let result = u32::try_from(raw_result).map_err(|_| raw_result).map(|res| res as i32);
prop_assert_eq!(result, Ok(a.wrapping_pow(b)));
}

#[test]
fn i32_checked_shr(a: i32, b in 0i32..32i32) {
let mut harness = TestByEmulationHarness::default();

harness
.emulator
.load_module(
Box::new(
Module::load_intrinsic("intrinsics::i32", &harness.context.session.codemap)
.expect("parsing failed"),
)
.freeze(),
)
.expect("failed to load intrinsics::i32");

let a_felt = Felt::new(a as u32 as u64);
let b_felt = Felt::new(b as u32 as u64);
let shr = "intrinsics::i32::checked_shr".parse().unwrap();
let mut stack = harness.invoke(shr, &[b_felt, a_felt]).expect("execution failed");
harness.emulator.stop();

prop_assert_eq!(stack.len(), 1);
let raw_result = stack.pop().unwrap().as_int();
let result = u32::try_from(raw_result).map_err(|_| raw_result).map(|res| res as i32);
prop_assert_eq!(result, Ok(a >> b));
}
}

0 comments on commit 491ec6b

Please sign in to comment.