Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
In qast_trig.t compare to a given epsilon as we get slightly differen…
…t results for different implementations of trigonometric functions.

Add qast_output_is_approx to t/helper.t we use for that.
  • Loading branch information
pmurias committed Feb 17, 2013
1 parent f91c444 commit aba0d5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
20 changes: 17 additions & 3 deletions t/helper.nqp
Expand Up @@ -65,9 +65,26 @@ sub run_qast($qast) is export {

my $output := subst(slurp('QAST2JASTOutput.output'), /\r\n/, "\n", :global);

#unlink('QAST2JASTOutput.dump');
#unlink('QAST2JASTOutput.class');
unlink('QAST2JASTOutput.output');

QASTResult.new(:output($output),:status($exit),:duration($time));
}

sub qast_output_is_approx($qast_maker,$expected, $desc = '') is export {
my $tol := nqp::abs_n($expected) < 1e-6 ?? 1e-5 !! nqp::abs_n($expected) * 1e-6;
my $output := run_qast($qast_maker()).output;
if nqp::abs_n($output - $expected) <= $tol {
ok(1, $desc);
}
else {
ok(0, $desc);
say("# got: $output");
say("# expected approximately: $expected");
}
}

sub qast_test($qast_maker, $expected, $desc = '') is export {
my $output := run_qast($qast_maker()).output;
if $output eq $expected {
Expand All @@ -78,9 +95,6 @@ sub qast_test($qast_maker, $expected, $desc = '') is export {
say("# got: $output");
say("# expected: $expected");
}
#unlink('QAST2JASTOutput.dump');
#unlink('QAST2JASTOutput.class');
unlink('QAST2JASTOutput.output');
}

sub spurt($file, $stuff) is export {
Expand Down
28 changes: 14 additions & 14 deletions t/qast/qast_trig.t
Expand Up @@ -3,22 +3,22 @@ use helper;
plan(13);

my @ops := (
("sin_n", 1, "0.8414709848078965"),
("asin_n", 1, "1.5707963267948966"),
("cos_n", 1, "0.5403023058681398"),
("acos_n", 1, "0"),
("tan_n", 1, "1.5574077246549023"),
("atan_n", 1, "0.7853981633974483"),
("sec_n", 1, "1.8508157176809255"),
("asec_n", 1, "0"),
("sinh_n", 1, "1.1752011936438014"),
("cosh_n", 1, "1.543080634815244"),
("tanh_n", 1, "0.7615941559557649"),
("sech_n", 1, "0.6480542736638853"),
("sin_n", 1, 0.8414709848078965),
("asin_n", 1, 1.5707963267948966),
("cos_n", 1, 0.5403023058681398),
("acos_n", 1, 0),
("tan_n", 1, 1.5574077246549023),
("atan_n", 1, 0.7853981633974483),
("sec_n", 1, 1.8508157176809255),
("asec_n", 1, 0),
("sinh_n", 1, 1.1752011936438014),
("cosh_n", 1, 1.543080634815244),
("tanh_n", 1, 0.7615941559557649),
("sech_n", 1, 0.6480542736638853),
);

for @ops -> $op {
qast_test(
qast_output_is_approx(
-> {
my $block := QAST::Block.new(
QAST::Op.new(
Expand All @@ -34,7 +34,7 @@ for @ops -> $op {
QAST::BVal.new( :value($block) )
)))
},
$op[2] ~ "\n",
$op[2],
$op[0] ~ " works");
}

Expand Down

0 comments on commit aba0d5c

Please sign in to comment.