Skip to content

Commit

Permalink
Merge pull request #810 from 0xPolygonMiden/hacka-test-assert-against…
Browse files Browse the repository at this point in the history
…-int

debug: convert from montgomery form prior to assert
  • Loading branch information
hackaugusto authored Apr 5, 2023
2 parents f5bdf0c + 04a016d commit 2690d5c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ impl Test {
/// Builds a final stack from the provided stack-ordered array and asserts that executing the
/// test will result in the expected final stack state.
pub fn expect_stack(&self, final_stack: &[u64]) {
let expected = convert_to_stack(final_stack);
let result = self.get_last_stack_state();

assert_eq!(expected, result);
assert_eq!(stack_to_top_ints(final_stack), stack_to_ints(&result));
}

/// Executes the test and validates that the process memory has the elements of `expected_mem`
Expand Down Expand Up @@ -179,10 +177,8 @@ impl Test {
&self,
final_stack: &[u64],
) -> Result<(), proptest::prelude::TestCaseError> {
let expected = convert_to_stack(final_stack);
let result = self.get_last_stack_state();

proptest::prop_assert_eq!(expected, result);
proptest::prop_assert_eq!(stack_to_top_ints(final_stack), stack_to_ints(&result));

Ok(())
}
Expand Down Expand Up @@ -254,13 +250,14 @@ impl Test {
// HELPER FUNCTIONS
// ================================================================================================

/// Takes an array of u64 values and builds a stack, preserving their order and converting them to
/// field elements.
pub fn convert_to_stack(values: &[u64]) -> [Felt; STACK_TOP_SIZE] {
let mut result = [Felt::ZERO; STACK_TOP_SIZE];
for (&value, result) in values.iter().zip(result.iter_mut()) {
*result = Felt::new(value);
}
/// Converts an array of Felts into u64
pub fn stack_to_ints(values: &[Felt]) -> Vec<u64> {
values.iter().map(|e| (*e).as_int()).collect()
}

pub fn stack_to_top_ints(values: &[u64]) -> Vec<u64> {
let mut result: Vec<u64> = values.to_vec();
result.resize(STACK_TOP_SIZE, 0);
result
}

Expand Down

0 comments on commit 2690d5c

Please sign in to comment.