Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2015 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0838392ab4b6f943e7ad to your computer and use it in GitHub Desktop.
Save anonymous/0838392ab4b6f943e7ad to your computer and use it in GitHub Desktop.
[jdv@wieldy ~]$ cat test.p6
use v6;
use Test;
sub infix:<≈> ($a, $b, :$desc) {
my $ok = $a ~~ $b;
return $ok unless $desc;
ok($ok, $desc);
unless $ok {
diag("expected: $b.perl()");
diag("got: $a");
}
return $ok;
}
sub infix:<±> ($num, $tolerance) is tighter(&infix:<≈>) {
$num-$tolerance .. $num+$tolerance
}
say 2.25 ≈ 1.3 ± $_ for 0.5, 1;
2.25 ≈ 1.3 ± $_ :desc("foo $_") for 0.5, 1;
done-testing;
[jdv@wieldy ~]$ perl6 test.p6
False
True
not ok 1 - foo 0.5
# Failed test 'foo 0.5'
# at test.p6 line 7
# expected: 0.8..1.8
# got: 2.25
ok 2 - foo 1
1..2
# Looks like you failed 1 test of 2
[jdv@wieldy ~]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment