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

PHP test indexed array comparison #72

Open
PootieT opened this issue May 19, 2023 · 0 comments
Open

PHP test indexed array comparison #72

PootieT opened this issue May 19, 2023 · 0 comments

Comments

@PootieT
Copy link

PootieT commented May 19, 2023

example problem: HumanEval_26_remove_duplicates

function test(): void {
    print_r(candidate(array(1, 2, 3, 2, 4, 3, 5))); // this gives
//    Array
//(
//    [0] => 1
//    [4] => 4
//    [6] => 5
//)
    if (candidate(array(1, 2, 3, 2, 4, 3, 5)) !== array(1, 4, 5)) { throw new Exception("Test failed!"); }
}

sometimes, the built-in array processing functions (array_filter for example) in PHP keeps the original index of the array, make this test fail, but somehow I feel like this should be considered a pass? (again, this maybe have been debated before, but just throwing it out there)

A possible solution is what was discussed here

function array_equal($a, $b) {
    return (
         is_array($a) 
         && is_array($b) 
         && count($a) == count($b) 
         && array_diff($a, $b) === array_diff($b, $a)
    );
}

// and then for tests
if (!array_equal(candidate(array(1, 2, 3, 2, 4, 3, 5)),array(1, 4, 5))) {throw new Exception("Test failed!"); };
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

No branches or pull requests

1 participant