Skip to content

Commit

Permalink
Add tests for new hint
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Mar 8, 2023
1 parent 38c1241 commit daa97dc
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/hint_processor/builtin_hint_processor/poseidon_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,74 @@ pub fn n_more_than_2(
};
insert_value_into_ap(vm, value)
}

#[cfg(test)]
mod tests {
use crate::any_box;
use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor;
use crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use crate::hint_processor::builtin_hint_processor::poseidon_utils::HashMap;
use crate::hint_processor::hint_processor_definition::HintProcessor;
use crate::hint_processor::hint_processor_definition::HintReference;
use crate::types::exec_scope::ExecutionScopes;
use crate::types::relocatable::MaybeRelocatable;
use crate::vm::errors::memory_errors::MemoryError;
use crate::vm::vm_core::VirtualMachine;
use crate::vm::vm_memory::memory::Memory;
use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
use crate::{hint_processor::builtin_hint_processor::hint_code, utils::test_utils::*};
use assert_matches::assert_matches;
use std::any::Any;

#[test]
fn run_n_more_than_10_true() {
let hint_code = hint_code::NONDET_N_MORE_THAN_10;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 21)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 1)];
}

#[test]
fn run_n_more_than_10_false() {
let hint_code = hint_code::NONDET_N_MORE_THAN_10;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 9)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 0)];
}

#[test]
fn run_n_more_than_2_true() {
let hint_code = hint_code::NONDET_N_MORE_THAN_2;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 6)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 1)];
}

#[test]
fn run_n_more_than_2_false() {
let hint_code = hint_code::NONDET_N_MORE_THAN_2;
let mut vm = vm!();
vm.set_ap(3);
vm.segments = segments![((1, 0), 1)];
vm.set_fp(1);
let ids_data = ids_data!("n");
assert_matches!(run_hint!(vm, ids_data, hint_code), Ok(()));
//Check hint memory inserts
check_memory![vm.segments.memory, ((1, 3), 0)];
}
}

1 comment on commit daa97dc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: daa97dc Previous: 91bd6b0 Ratio
cairo_run(cairo_programs/benchmarks/uint256_integration_benchmark.json) 1606649457 ns/iter (± 44697447) 1222491940 ns/iter (± 3372193) 1.31

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.