I'm trying to make tests for a function that throws an exception with this code:
use v6;
use Test;
plan *;
use lib "lib";
use Math::ConvergenceMethods;
sub f ($x) {return $x + 1;}
{
is-approx: bisection(&f, -2, 0), -1;
dies-ok: { bisection(&f, 3, 2) }, "Incorrect arguments";
}
done-testing;
And it returns this warnings when I run it:
WARNINGS for /home/antonio/Code/perl6/Math-ConvergenceMethods/t/bisection.t:
Useless use of "-" in expression "-1" in sink context (line 13)
Useless use of constant string "Incorrect arguments" in sink context (lines 14, 14)
How can I fix it?
The foo
in a statement of the form:
foo: ...
is a label where the ...
is the statement that it labels.
So the statement you've written is the same as:
bisection(&f, -2, 0), -1;
which leaves the -1
in sink context, hence the error message.
(The message is somewhat LTA because your mistake is clearly that you thought the label syntax was a function calling syntax and while the error message does indicate the error -- in sink context
-- the Useless use of "-"
is additional detail that doesn't help and probably added to your confusion.)
See also What's the difference these two function calling conventions?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With