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

Bug: cairo-test byte_array_test.cairo tests fail #471

Closed
edg-l opened this issue Mar 12, 2024 · 3 comments · Fixed by #549
Closed

Bug: cairo-test byte_array_test.cairo tests fail #471

edg-l opened this issue Mar 12, 2024 · 3 comments · Fixed by #549
Labels
bug Something isn't working odhack
Milestone

Comments

@edg-l
Copy link
Collaborator

edg-l commented Mar 12, 2024

Likely related to spans?

// ./cairo-tests/src/byte_array_test.cairo

// TODO: segfault
#[test]
#[ignore]
fn test_reverse() {
    // Arrays of length < 16
    let ba: ByteArray = "abc";
    let ba_rev: ByteArray = "cba";
    let palindrome: ByteArray = "rotator";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of length 16
    let ba: ByteArray = "my length is 16.";
    let ba_rev: ByteArray = ".61 si htgnel ym";
    let palindrome: ByteArray = "nolemon  nomelon";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of 16 < length < 31
    let ba: ByteArray = "I am a medium byte array";
    let ba_rev: ByteArray = "yarra etyb muidem a ma I";
    let palindrome: ByteArray = "nolemon  nomelon";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of length 31
    let ba: ByteArray = "I didn't find a good palindrome";
    let ba_rev: ByteArray = "emordnilap doog a dnif t'ndid I";
    let palindrome: ByteArray = "kayak level rotator level kayak";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of 31 < length < 47 (31+16)
    let ba: ByteArray = "This time I did find a good palindrome!";
    let ba_rev: ByteArray = "!emordnilap doog a dnif did I emit sihT";
    let palindrome: ByteArray = "noitneverpropagatesifisetagaporprevention";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of length 47 (31+16)
    let ba: ByteArray = "I have found a palindrome, exactly 47 in length";
    let ba_rev: ByteArray = "htgnel ni 74 yltcaxe ,emordnilap a dnuof evah I";
    let palindrome: ByteArray = "onacloverifaliveeruptsavastpureevilafirevolcano";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');

    // Arrays of length > 47 (31+16)
    let ba: ByteArray = "This palindrome is not as good, but at least it's long enough";
    let ba_rev: ByteArray = "hguone gnol s'ti tsael ta tub ,doog sa ton si emordnilap sihT";
    let palindrome: ByteArray = "docnoteidissentafastneverpreventsafatnessidietoncod";
    assert_ne(@ba, @ba.rev(), 'ba == ba.rev()');
    assert_ne(@ba_rev, @ba_rev.rev(), 'ba_rev == ba_rev.rev()');
    assert_eq(@ba, @ba_rev.rev(), 'ba != ba_rev.rev()');
    assert_eq(@palindrome, @palindrome.rev(), 'palindrome is not a palindrome');
}
@edg-l edg-l added the bug Something isn't working label Mar 12, 2024
@igaray igaray added this to Starknet Mar 12, 2024
@igaray igaray added this to the 0.1 milestone Mar 12, 2024
@igaray igaray moved this to Backlog in Starknet Mar 13, 2024
@igaray igaray moved this from Backlog to Todo in Starknet Mar 13, 2024
@igaray igaray added the odhack label Mar 18, 2024
@wugalde19
Copy link
Contributor

wugalde19 commented Mar 18, 2024

Hi @edg-l @igaray
Can I take care of this, please?

@azteca1998
Copy link
Collaborator

Hello, that specific issue has been fixed with the array rewrite. The same PR introduced other failing tests, which are:

  • Array equality tests (and reversal).
  • Byte array equality tests.

@edg-l
Copy link
Collaborator Author

edg-l commented Apr 9, 2024

fn main() -> bool {
    let byte_array: ByteArray = "a";
    byte_array == "a"
}

reduced failing program

@azteca1998 azteca1998 linked a pull request Apr 25, 2024 that will close this issue
5 tasks
@github-project-automation github-project-automation bot moved this from Todo to Done in Starknet Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working odhack
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants