-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
contain_exactly
matcher spins forever, never finishing whatever it's supposed to be doing
#1006
Comments
Thanks for the bug report! Unfortunately, the large amount of flexibility provided by the You can work around this by not using expect(actual_path_names.sort).to eq(expected_path_names.sort) Of course, that's not ideal, but it should at least unblock you. Long term, I'd love for us to improve
Here we can see that for a string, |
You say large arrays, but my array was only about 200 elements in size... And if I randomly move some elements around, suddenly it's much, much faster again, even though only a couple of elements changed. It doesn't really make sense to me. |
Can you paste the re-ordering that makes it faster?
…Sent from my iPhone
On Aug 2, 2017, at 11:44 AM, Trejkaz (pen name) ***@***.***> wrote:
You say large arrays, but my array was only about 200 elements in size... And if I randomly move some elements around, suddenly it's much, much faster again, even though only a couple of elements changed. It doesn't really make sense to me.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Turns out I couldn't get it to happen from the original example. But my original test failure did fail instantly, so I converted that to the same style, and I get:
The sizes:
So I guess each list is half the size, but it completes much faster than 1/4 of the time. Actually, I haven't yet seen the other example complete. :) So actually just looking at the lists, it seems like the main difference is that this one has a unique element at the front before the run of identical elements, whereas in the other example, it starts with a run of identical elements. |
Well, I ruled out that theory because I tried the original example with a "y0" at the front, and I still get a hang. So I have no idea what makes it run so much faster in one case and not the other. |
So this is interesting... If:
I get a hang with:
But no hang with:
Even though the latter is much longer. :) |
Thanks, that's a useful example. I'll dig into it. |
I'm not sure how much progress I can make here, but just in case it's useful to others solving this, I've move @trejkaz's example into a spec at https://github.com/kaiwren/rspec-expectations/tree/1006-contains-exactly-hangs (this isn't merge-able, just useful to get started) |
The optimisation suggested in #1006 (comment) should solve this particular case as reported, but if anyone is motivated to improve the contain_exactly matcher in a more general way, the following may be of use: The problem that PairingsMaximizer solves is finding a maximum cardinality matching for a bipartite graph. Replacing the current brute force algorithm with a solution such as the Hopcroft-Karp algorithm should give far better results in the general case. |
Speed up the ContainExactly matcher by pre-emptively matching up corresponding elements in the expected and actual arrays. This addresses rspec#1006, rspec#1161. This PR is a collaboration between me and @genehsu based on a couple of our earlier PRs and discussion that resulted: 1) rspec#1325 2) rspec#1328 Co-authored-by: Gene Hsu (@genehsu)
Speed up the ContainExactly matcher by pre-emptively matching up corresponding elements in the expected and actual arrays. This addresses rspec#1006, rspec#1161. This PR is a collaboration between me and @genehsu based on a couple of our earlier PRs and discussion that resulted: 1) rspec#1325 2) rspec#1328 Co-authored-by: Gene Hsu (@genehsu)
Speed up the ContainExactly matcher by pre-emptively matching up corresponding elements in the expected and actual arrays. This addresses rspec#1006, rspec#1161. This PR is a collaboration between me and @genehsu based on a couple of our earlier PRs and discussion that resulted: 1) rspec#1325 2) rspec#1328 Co-authored-by: Gene Hsu (@genehsu)
For some reason, this example never completes:
RSpec v3.6.0
JRuby v9.1.6.0, MRI v2.4.0
The text was updated successfully, but these errors were encountered: