Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Test::More fails...

by Bod (Parson)
on May 30, 2023 at 09:20 UTC ( [id://11152504]=note: print w/replies, xml ) Need Help??


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

Here's my guess for your first issue.....it gets executed at run-time - so it has not yet been executed when you hit the BEGIN block and launch in to your first test

That seems sensible. It also seems odd because I didn't write that code - it is part of the boilerplate produced by Module::Starter

I don't have an immediate guess for the second issue

At least I am not missing something obvious :)

$comp_pass2 should contain a floating point between -1 and +1. If the two stringified vectors are the same (like they are in the test), then the result should be +1. The compare method returns the Cosine Similarity of the two vectors derived from the test strings

Replies are listed 'Best First'.
Re^3: Test::More fails...
by haukex (Archbishop) on May 30, 2023 at 12:19 UTC

      compare will only ever return 1 when the two vectors it is given are identical. In practice, this will almost certainly never happen. If the default model is used, the vectors are 1536 dimensions. For the tests, I have artificially created much smaller, deliberately identical vectors.

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

        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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found