Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Test::More fails...

by haukex (Archbishop)
on May 30, 2023 at 13:40 UTC ( [id://11152518]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Test::More fails...
in thread Test::More fails...

compare will only ever return 1 when the two vectors it is given are identical. In practice, this will almost certainly never happen.

Well, it's still good to test the edge cases, as this thread shows.

The return value of compare is the return value of cosine in Data::CosineSimilarity

From the source that appears to be the result of a bunch of multiplications and divisions, and assuming there's some floating-point numbers in there, then what I wrote above likely applies. A lot of testing frameworks have functions to compare floating point numbers down to a certain number of decimal places, but it appears this isn't built in to Test::More (though for some reason I remembered incorrectly that it was). Though there's probably a module or two that adds this functionality, a workaround is:

use Test::More tests=>1; my $x = 1.00000001; is sprintf("%.5f", $x), "1.00000";

Replies are listed 'Best First'.
Re^6: Test::More fails...
by hippo (Bishop) on May 30, 2023 at 13:49 UTC

    I usually end up using cmp_ok like this:

    cmp_ok abs($have - $want), '<', $tolerance;

    It's so short that I've never bothered to look for another Test::* module to do it.


    🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11152518]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found