-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test adding programs using non squashed Felt252Dict #1797
Changes from 6 commits
35ed2dc
bc9aa71
14f498b
89afb57
4c203ed
fe81f82
974c209
ffbccac
0f36fb5
e6575e1
72cf8e2
320c86c
9f111a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,13 +320,6 @@ mod tests { | |
None | ||
)] | ||
#[case("array_integer_tuple.cairo", "[1] 1", "[1 1 1]", None, None)] | ||
#[case( | ||
"felt_dict.cairo", | ||
"{66675: [8 9 10 11] 66676: [1 2 3]}", | ||
"[66675 4 8 9 10 11 66676 3 1 2 3]", | ||
None, | ||
None | ||
)] | ||
#[case("felt_span.cairo", "[8 9 10 11]", "[4 8 9 10 11]", None, None)] | ||
#[case("nullable_dict.cairo", "", "[]", None, None)] | ||
#[case( | ||
|
@@ -475,6 +468,50 @@ mod tests { | |
assert_matches!(run(args), Ok(Some(res)) if res == expected_output, "Program {} failed with flags {}", program, extra_flags.concat()); | ||
} | ||
|
||
#[rstest] | ||
#[case( | ||
"dict_with_struct_non_squash.cairo", | ||
"{0: 1 true 1: 1 false 2: 1 true}", | ||
None | ||
)] | ||
#[case("nullable_box_vec_non_squash.cairo", "{0: 10 1: 20 2: 30} 3", None)] | ||
#[case( | ||
"felt_dict_non_squash.cairo", | ||
"{66675: [8 9 10 11] 66676: [1 2 3]}", | ||
None | ||
)] | ||
fn test_run_progarm_non_proof( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here explaining why we test these programs in a different way than the others |
||
#[case] program: &str, | ||
#[case] expected_output: &str, | ||
#[case] inputs: Option<&str>, | ||
#[values( | ||
&["--cairo_pie_output", "/dev/null"], // Non proof-mode | ||
)] | ||
extra_flags: &[&str], | ||
) { | ||
let common_flags = &[ | ||
"--print_output", | ||
"--trace_file", | ||
"/dev/null", | ||
"--memory_file", | ||
"/dev/null", | ||
"--layout", | ||
"all_cairo", | ||
]; | ||
let mut args = vec!["cairo1-run"]; | ||
let filename = format!("../cairo_programs/cairo-1-programs/{}", program); | ||
|
||
args.push(&filename); | ||
args.extend_from_slice(common_flags); | ||
args.extend_from_slice(extra_flags); | ||
if let Some(inputs) = inputs { | ||
args.extend_from_slice(&["--args", inputs]) | ||
} | ||
let args = args.iter().cloned().map(String::from); | ||
let expected_output = expected_output; | ||
assert_matches!(run(args), Ok(Some(res)) if res == expected_output, "Program {} failed with flags {}", program, extra_flags.concat()); | ||
} | ||
|
||
#[rstest] | ||
#[case(["cairo1-run", "../cairo_programs/cairo-1-programs/serialized_output/with_input/branching.cairo", "--layout", "all_cairo", "--cairo_pie_output", "/dev/null"].as_slice())] | ||
#[case(["cairo1-run", "../cairo_programs/cairo-1-programs/serialized_output/with_input/branching.cairo", "--layout", "all_cairo", "--proof_mode"].as_slice())] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use core::nullable::{nullable_from_box, match_nullable, FromNullableResult}; | ||
|
||
|
||
#[derive(Drop, Copy)] | ||
struct FP16x16 { | ||
mag: u32, | ||
sign: bool | ||
} | ||
|
||
fn main() -> Felt252Dict<Nullable<FP16x16>> { | ||
// Create the dictionary | ||
let mut d: Felt252Dict<Nullable<FP16x16>> = Default::default(); | ||
|
||
let box_a = BoxTrait::new(identity(FP16x16 { mag: 1, sign: false })); | ||
let box_b = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); | ||
let box_c = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); | ||
|
||
// Insert it as a `Span` | ||
d.insert(0, nullable_from_box(box_c)); | ||
d.insert(1, nullable_from_box(box_a)); | ||
d.insert(2, nullable_from_box(box_b)); | ||
|
||
d | ||
} | ||
|
||
// TODO: remove this temporary fix once fixed in cairo | ||
#[inline(never)] | ||
fn identity<T>(t: T) -> T { t } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use core::nullable::{nullable_from_box, match_nullable, FromNullableResult}; | ||
|
||
|
||
#[derive(Drop, Copy)] | ||
struct FP16x16 { | ||
mag: u32, | ||
sign: bool | ||
} | ||
|
||
fn main() -> SquashedFelt252Dict<Nullable<FP16x16>> { | ||
// Create the dictionary | ||
let mut d: Felt252Dict<Nullable<FP16x16>> = Default::default(); | ||
|
||
let box_a = BoxTrait::new(identity(FP16x16 { mag: 1, sign: false })); | ||
let box_b = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); | ||
let box_c = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); | ||
|
||
// Insert it as a `Span` | ||
d.insert(0, nullable_from_box(box_c)); | ||
d.insert(1, nullable_from_box(box_a)); | ||
d.insert(2, nullable_from_box(box_b)); | ||
|
||
d.squash() | ||
} | ||
|
||
// TODO: remove this temporary fix once fixed in cairo | ||
#[inline(never)] | ||
fn identity<T>(t: T) -> T { t } |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont get why we change this file, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
struct NullableVec<T> { | ||
items: Felt252Dict<Nullable<Box<T>>>, | ||
len: usize, | ||
} | ||
|
||
fn main() -> NullableVec<u32> { | ||
let mut d: Felt252Dict<Nullable<Box<u32>>> = Default::default(); | ||
|
||
// Populate the dictionary | ||
d.insert(0, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(10))))); | ||
d.insert(1, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(20))))); | ||
d.insert(2, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(30))))); | ||
|
||
// Return NullableVec | ||
NullableVec { | ||
items: d, | ||
len: 3, | ||
} | ||
} | ||
|
||
// TODO: remove this temporary fix once fixed in cairo | ||
#[inline(never)] | ||
fn identity<T>(t: T) -> T { t } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add endline |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
struct NullableVec<T> { | ||
items: SquashedFelt252Dict<Nullable<Box<T>>>, | ||
len: usize, | ||
} | ||
|
||
fn main() -> NullableVec<u32> { | ||
let mut d: Felt252Dict<Nullable<Box<u32>>> = Default::default(); | ||
|
||
// Populate the dictionary | ||
d.insert(0, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(10))))); | ||
d.insert(1, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(20))))); | ||
d.insert(2, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(30))))); | ||
|
||
// Return NullableVec | ||
NullableVec { | ||
items: d.squash(), | ||
len: 3, | ||
} | ||
} | ||
|
||
// TODO: remove this temporary fix once fixed in cairo | ||
#[inline(never)] | ||
fn identity<T>(t: T) -> T { t } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we removing this test?