Skip to content
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

Add remaining assert_xx! comparison test macros #4936

Merged
merged 8 commits into from
Feb 13, 2024

Conversation

iamvukasin
Copy link
Contributor

@iamvukasin iamvukasin commented Jan 27, 2024

This change is Reviewable

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)

a discussion (no related file):
do you know why these don't exist in rust - and why is our situation different?


@iamvukasin
Copy link
Contributor Author

iamvukasin commented Feb 5, 2024

TBH initially I didn't check if and why Rust didn't support all of them, but I did now. As they found out, these asserts are not used frequently. I don't have any data to prove if Cairo ones would or wouldn't be used more, but based on my experience of writing Cairo tests daily, they can be useful, especially since generic assert and assert! are not that helpful. Many of my tests are based on balance/timestamp checkings and it is helpful when you know why your assert is failing (and which values are being checked).

In an ideal world, this could be a standalone helper library like all_asserts. I wouldn't bother opening a PR for this if Cairo had a straightforward way of defining custom macros.

The biggest reason why Cairo situation is different is the debugging experience. In Rust, I don't need these asserts as I can just put a breakpoint in an IDE and check the values, but Cario debugging still relies on printing or going low level. I don't want to go into too much details, but IMO this can sometimes make life easier. :)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)

a discussion (no related file):
@gilbens-starkware for 2nd eye.


Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)


corelib/src/test/testing_test.cairo line 84 at r2 (raw file):

    assert_ge!(2, 1);
    assert_ge!(2, 2);
}

add types - as felt252s aren't ordered.

Code quote:

#[test]
fn test_assert_lt_with_description() {
    assert_lt!(1, 2, "Description");
}

#[test]
fn test_assert_lt_no_description() {
    assert_lt!(1, 2);
}

#[test]
fn test_assert_le_with_description() {
    assert_le!(1, 2, "Description");
    assert_le!(1, 1, "Description");
}

#[test]
fn test_assert_le_no_description() {
    assert_le!(1, 2);
    assert_le!(1, 1);
}

#[test]
fn test_assert_gt_with_description() {
    assert_gt!(2, 1, "Description");
}

#[test]
fn test_assert_gt_no_description() {
    assert_gt!(2, 1);
}

#[test]
fn test_assert_ge_with_description() {
    assert_ge!(2, 1, "Description");
    assert_ge!(2, 2, "Description");
}

#[test]
fn test_assert_ge_no_description() {
    assert_ge!(2, 1);
    assert_ge!(2, 2);
}

@iamvukasin iamvukasin requested a review from orizi February 8, 2024 09:14
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @iamvukasin)

@orizi orizi enabled auto-merge February 8, 2024 09:31
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @iamvukasin)

a discussion (no related file):
Please rebase and make sure tests pass, these didn't pass since we approved.


Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @iamvukasin)


corelib/src/test/testing_test.cairo line 43 at r6 (raw file):

#[test]
fn test_assert_lt_with_description() {

It is possibly due to the test being u256, just change to u8 and check the tests are fine.

auto-merge was automatically disabled February 13, 2024 13:51

Head branch was pushed to by a user without write access

@iamvukasin
Copy link
Contributor Author

Done. Had to decrease available_gas as it was failing even with u8.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @iamvukasin)

@orizi orizi added this pull request to the merge queue Feb 13, 2024
Merged via the queue into starkware-libs:main with commit 7179488 Feb 13, 2024
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants