-
Notifications
You must be signed in to change notification settings - Fork 39
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
example just for math*.cairo files #455
Draft
jobez
wants to merge
2
commits into
keep-starknet-strange:main
Choose a base branch
from
jobez:integration/add_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
%builtins range_check | ||
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. we commit cairo files. i arbitrarily chose to just move the files in the great https://github.com/lambdaclass/cairo-vm/tree/main/cairo_programs that matched "math.cairo |
||
|
||
from starkware.cairo.common.math_cmp import ( | ||
is_not_zero, | ||
is_nn, | ||
is_le, | ||
is_nn_le, | ||
is_in_range, | ||
is_le_felt, | ||
) | ||
|
||
func main{range_check_ptr: felt}() { | ||
// is_not_zero | ||
let a = is_not_zero(10); | ||
assert a = 1; | ||
let b = is_not_zero(1); | ||
assert b = 1; | ||
let c = is_not_zero(0); | ||
assert c = 0; | ||
|
||
// is_nn | ||
let d = is_nn(0); | ||
assert d = 1; | ||
let e = is_nn(88); | ||
assert e = 1; | ||
let f = is_nn(-88); | ||
assert f = 0; | ||
|
||
// is_le | ||
let g = is_le(1, 2); | ||
assert g = 1; | ||
let h = is_le(2, 2); | ||
assert h = 1; | ||
let i = is_le(56, 20); | ||
assert i = 0; | ||
|
||
// is_nn_le | ||
let j = is_nn_le(1, 2); | ||
assert j = 1; | ||
let k = is_nn_le(2, 2); | ||
assert k = 1; | ||
let l = is_nn_le(56, 20); | ||
assert l = 0; | ||
|
||
// is_in_range | ||
let m = is_in_range(1, 2, 3); | ||
assert m = 0; | ||
let n = is_in_range(2, 2, 5); | ||
assert n = 1; | ||
let o = is_in_range(56, 20, 120); | ||
assert o = 1; | ||
|
||
// is_le_felt | ||
let p = is_le_felt(1, 2); | ||
assert p = 1; | ||
let q = is_le_felt(2, 2); | ||
assert q = 1; | ||
let r = is_le_felt(56, 20); | ||
assert r = 0; | ||
|
||
return (); | ||
} |
120 changes: 120 additions & 0 deletions
120
cairo_programs/math_cmp_and_pow_integration_tests.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
%builtins range_check | ||
|
||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.pow import pow | ||
from starkware.cairo.common.math_cmp import ( | ||
is_not_zero, | ||
is_nn, | ||
is_le, | ||
is_nn_le, | ||
is_in_range, | ||
is_le_felt, | ||
) | ||
|
||
const CONSTANT = 3 ** 10; | ||
|
||
func fill_array_with_pow{range_check_ptr}( | ||
array_start: felt*, base: felt, step: felt, exp: felt, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let (res) = pow(base + step, exp); | ||
assert array_start[iter] = res; | ||
return fill_array_with_pow(array_start, base + step, step, exp, iter + 1, last); | ||
} | ||
|
||
func test_is_not_zero{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_not_zero(base_array[iter]); | ||
assert new_array[iter] = res; | ||
return test_is_not_zero(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_nn{range_check_ptr}(base_array: felt*, new_array: felt*, iter: felt, last: felt) -> ( | ||
) { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_nn(base_array[iter]); | ||
assert new_array[iter] = res; | ||
return test_is_nn(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_le{range_check_ptr}(base_array: felt*, new_array: felt*, iter: felt, last: felt) -> ( | ||
) { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_le(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_le(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_nn_le{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_nn_le(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_nn_le(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_in_range{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_in_range(CONSTANT, base_array[iter], base_array[iter + 1]); | ||
assert new_array[iter] = res; | ||
return test_is_in_range(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_le_felt{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_le_felt(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_le_felt(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func run_tests{range_check_ptr}(array_len: felt) -> () { | ||
alloc_locals; | ||
let (array: felt*) = alloc(); | ||
fill_array_with_pow(array, 0, 3, 3, 0, array_len); | ||
|
||
let (array_is_not_zero: felt*) = alloc(); | ||
test_is_not_zero(array, array_is_not_zero, 0, array_len); | ||
|
||
let (array_is_nn: felt*) = alloc(); | ||
test_is_nn(array, array_is_nn, 0, array_len); | ||
|
||
let (array_is_le: felt*) = alloc(); | ||
test_is_le(array, array_is_le, 0, array_len); | ||
|
||
let (array_is_nn_le: felt*) = alloc(); | ||
test_is_nn_le(array, array_is_nn_le, 0, array_len); | ||
|
||
let (array_is_in_range: felt*) = alloc(); | ||
test_is_in_range(array, array_is_in_range, 0, array_len - 1); | ||
|
||
let (array_is_le_felt: felt*) = alloc(); | ||
test_is_le_felt(array, array_is_le_felt, 0, array_len); | ||
|
||
return (); | ||
} | ||
|
||
func main{range_check_ptr}() { | ||
run_tests(10); | ||
return (); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just for the sake of demonstration i created a separate entry point to run the integration tests that