matcher

Does an RSpec2 matcher for matching Hashes exist?

99封情书 提交于 2019-12-04 16:26:38
问题 Note to future readers: think RSpec does not consider your Hashes equal? One might be an OrderedHash, but from the regular RSpec output you can't tell. This was the problem that prompted this post. Original question: Suppose I have a spec where I want to test that a method generates the appropriate Hash. it 'should generate the Hash correctly' do expected = {:foo => 1, 'baz' => 2} subject.some_method_that_should_generate_the_hash.should == expected end This often fails, because different

How to Access Points location on OpenCV Matcher?

。_饼干妹妹 提交于 2019-12-04 11:22:33
I am using this FLANN matcher algorithm to match interest points in 2 pictures the code is displayed below). There is a moment when the code finds a list of matched points: std::vector<DMatch> good_matches; I would like to get the points localization (x,y) in both pictures. To create a displacement map. How could I access these points localization? Cheers, #include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/nonfree/features2d.hpp" #include "opencv2/highgui/highgui.hpp" using namespace cv; void readme(); /** @function main */ int main(int argc, char** argv)

How to show custom failure messages in ScalaTest?

 ̄綄美尐妖づ 提交于 2019-12-04 07:48:53
问题 Does anyone know how to show a custom failure message in ScalaTest? For example: NumberOfElements() should equal (5) Shows the following message when it fails: 10 did not equal 5 But i want more descriptive message like: NumberOfElements should be 5. 回答1: You're the first to ask for such a feature. One way to achieve this is with withClue. Something like: withClue("NumberOfElements: ") { NumberOfElements() should be (5) } That should get you this error message: NumberOfElements: 10 was not

Matcher not finding overlapping words?

别等时光非礼了梦想. 提交于 2019-12-04 06:02:31
问题 I'm trying to take a string: String s = "This is a String!"; And return all 2-word pairs within that string. Namely: {"this is", "is a", "a String"} But right now, all I can get it to do is return: {"this is", "a String"} How can I define my while loop such that I can account for this lack of overlapping words? My code is as follows: (Really, I'd be happy with it just returning an int representing how many string subsets it found...) int count = 0; while(matcher.find()) { count += 1; } Thanks

How to terminate Matcher.find(), when its running too long?

寵の児 提交于 2019-12-04 05:08:24
Wondering about techniques for terminating long running regular expression matches (java matcher.find() method). Maybe subclassing Matcher and adding some logic to terminate after x number of iterations? Basically I'm generating regular expressions using a genetic algorithm, so I don't have a lot of control over them. Then I test each one against some text to see if they match a certain target area of the text. So since I'm sort of randomly generating these regular expressions, I get some crazy stuff going on, and it eats a ton of cpu and some find() calls take a while to terminate. I'd rather

ScalaTest - writing custom matchers

时间秒杀一切 提交于 2019-12-03 13:45:56
I am running into a problem while writing a custom matcher for NodeSeq: private def matchXML(expected: NodeSeq) = new Matcher[NodeSeq] { def apply(left: NodeSeq): MatchResult = MatchResult(left xml_== expected, "XML structure was not the same (watch spaces in tag texts)", "XML messages were equal") } This compiles, but the following piece of code: val expected : NodeSeq = ... val xml : NodeSeq = ... xml should matchXML(expected) causes: error: overloaded method value should with alternatives: (beWord: XMLStripDecoratorTests.this.BeWord)XMLStripDecoratorTests.this.ResultOfBeWordForAnyRef[scala

Does an RSpec2 matcher for matching Hashes exist?

假装没事ソ 提交于 2019-12-03 10:27:21
Note to future readers: think RSpec does not consider your Hashes equal? One might be an OrderedHash, but from the regular RSpec output you can't tell. This was the problem that prompted this post. Original question: Suppose I have a spec where I want to test that a method generates the appropriate Hash. it 'should generate the Hash correctly' do expected = {:foo => 1, 'baz' => 2} subject.some_method_that_should_generate_the_hash.should == expected end This often fails, because different Hashes with the same key-value pairs may return their pairs in a different ordered. Results look like:

Rspec view testing with capybara and rails3

淺唱寂寞╮ 提交于 2019-12-03 05:49:29
问题 I really like the way RSpec is able to separate controller and view tests but have some problems with getting capybara matchers to work in a view test. What i basically try to achieve is sth like this: describe "some page" do it "should render with lots of stuff" do assign .. render rendered.should have_button ('Any button') #or any capybara matcher, really end end I've seen some posts on the net showing how to configure capybara and rails3 to work smoothly with cucumber or rspec controller

How to appendReplacement on a Matcher group instead of the whole pattern?

ぐ巨炮叔叔 提交于 2019-12-03 05:41:05
问题 I am using a while(matcher.find()) to loop through all of the matches of a Pattern. For each instance or match of that pattern it finds, I want to replace matcher.group(3) with some new text. This text will be different for each one so I am using matcher.appendReplacement() to rebuild the original string with the new changes as it goes through. However, appendReplacement() replaces the entire Pattern instead of just the group. How can I do this but only modify the third group of the match

Android - Matcher.find() infinite

北城余情 提交于 2019-12-02 21:36:56
问题 I have implemented AsyncTask where the regular expression provided by the user is being used for matching huge html-code data. However, because some of the regular expressions contain a lot of quantifiers/backtracking, Matcher.find() goes infinite. I have tried to use InterruptibleCharSequence provided here: How to terminate Matcher.find(), when its running too long?, but it seems that charAt is never get called, so never interrupted. My last guess is to create a new process just to run this