in reply to Re^3: inconistent test results when using is_deeply to test an array returned from a function
in thread inconistent test results when using is_deeply to test an array returned from a function
I think the issue comes down to: how do I compare two arrays for equality. Note: the equality test needs to sort the arrays first or ignore array order
is_deeply is the best way to compare two data structures for equality. If the order of an array doesn't matter in the test, then it's fine to sort first: is_deeply([sort @got_files], [sort @expected_files]); (or you can sort the arrays earlier if you like). The other way to hold unsorted data would be with a hash (the difference being that an array allows duplicate values while a hash does not allow duplicate keys, and that an array will keep the order of its values while a hash will not), however is_deeply can also easily compare two hashes. So e.g. my %files = map { $_ => 1 } @files; is_deeply \%files, \%expect_files;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: inconistent test results when using is_deeply to test an array returned from a function
by APGRMF (Novice) on Sep 25, 2014 at 11:19 UTC | |
by kennethk (Abbot) on Sep 25, 2014 at 17:38 UTC | |
by APGRMF (Novice) on Sep 29, 2014 at 15:02 UTC |