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

Allow ApproximatelyMatcher to compare arrays #1368

Merged
merged 1 commit into from Jun 19, 2021

Conversation

ciaranmcnulty
Copy link
Member

As suggested in #1367

My only concern is that the Differ doesn't know the precision the Matcher used, so in some case the verbose diff could be misleading

@TiMESPLiNTER
Copy link

Regarding your concern: that's definitely not ideal, but the current message you get if you compare an array of floats with shouldBe() is misleading anyway. It says:

expected [array:11], but got [array:11].

But if you see the use of shouldBeApproximately() in a test case you're immediately kind of aware the you're dealing with some sort of precision problem, right?

@ciaranmcnulty
Copy link
Member Author

@TiMESPLiNTER If you pass the -v option you will see a diff

@TiMESPLiNTER
Copy link

TiMESPLiNTER commented Jan 18, 2021

@TiMESPLiNTER If you pass the -v option you will see a diff

True, but not if you compare an array with floats with shouldBe(). Then I just got the message mentioned above without a diff. Maybe a bug in the array diff?

See this example:

$ ./vendor/bin/phpspec run -vvv 


Timesplinter/Math                                                    
  17  - it calculates numbers
      expected [array:11], but got [array:11].
      
      
      
        21         $result = $this::calculate($values);
        22 
        23         $result->shouldBe([2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5]);
        24 
        25     }
        26 
      
       0 vendor/phpspec/phpspec/src/PhpSpec/Matcher/IdentityMatcher.php:59
         throw new PhpSpec\Exception\Example\NotEqualException("Expected [array:11...")

@ciaranmcnulty
Copy link
Member Author

ciaranmcnulty commented Jan 18, 2021

Odd, maybe open a new issue with a reproducer
Screenshot 2021-01-18 at 10 10 52

@drupol
Copy link
Contributor

drupol commented Jun 2, 2021

@TiMESPLiNTER What's the status of this?

@TiMESPLiNTER
Copy link

Somehow lost track of it and never ended up having this problem again because I never dealt with floating arrays since then. I guess the problem still exists though.

@ciaranmcnulty ciaranmcnulty merged commit fa4c67a into phpspec:main Jun 19, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants