Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Test::More fails...

by hv (Prior)
on May 29, 2023 at 23:46 UTC ( [id://11152488]=note: print w/replies, xml ) Need Help??


in reply to Test::More fails...

Here's my guess for your first issue: plan tests => 1; is a standard Perl statement, 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.

You could work around this by also putting the plan statement in a BEGIN block. However use Module (foo); is equivalent to BEGIN { require Module; Module->import(foo) }. So its action occurs at BEGIN time, just as required for this case.

I don't have an immediate guess for the second issue. If I were debugging this, my next steps would be a) to run the test program in isolation for more verbose output; then b) to use Devel::Peek to Dump($comp_pass2) directly after setting it - I can think of several types of value that would stringify as "1" but give a false result from $comp_pass2 == 1.

However your expectation of the function also seems odd: normally I would expect a comparator to return similar values to $a cmp $b or $a <=> $b, in particular returning 0 when the two values are equal. With your lengthy test strings it is hard to tell by eye, but I think they are the same.

Replies are listed 'Best First'.
Re^2: Test::More fails...
by Bod (Parson) on May 30, 2023 at 09:20 UTC
    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

        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found