Skip to content

Commit

Permalink
Add factorial tests (#1180)
Browse files Browse the repository at this point in the history
* Add factorial tests

* Change functions name
  • Loading branch information
pefontana authored Jun 13, 2023
1 parent f053646 commit 6d8d492
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cairo_programs/cairo-1-contracts/factorial.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[contract]
mod Factorial {

#[external]
fn factorial(n: felt252) -> felt252 {
if (n == 0) {
return 1;
}
n * factorial(n - 1)
}
}
33 changes: 33 additions & 0 deletions vm/src/tests/cairo_1_run_from_entrypoint_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use num_traits::Num;

use crate::tests::*;
use assert_matches::assert_matches;

Expand Down Expand Up @@ -96,6 +98,37 @@ fn fibonacci_3() {
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn factorial_50() {
let program_data = include_bytes!("../../../cairo_programs/cairo-1-contracts/factorial.casm");
run_cairo_1_entrypoint(
program_data.as_slice(),
0,
&[50.into()],
&[Felt252::from_str_radix(
"30414093201713378043612608166064768844377641568960512000000000000",
10,
)
.unwrap()],
);
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn factorial_2000() {
let program_data = include_bytes!("../../../cairo_programs/cairo-1-contracts/factorial.casm");
run_cairo_1_entrypoint(
program_data.as_slice(),
0,
&[2000.into()],
&[Felt252::from_str_radix(
"2570376556569900799903105814841036176886569861654260254942280653735904624674",
10,
)
.unwrap()],
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn u8_sqrt_9() {
Expand Down

0 comments on commit 6d8d492

Please sign in to comment.