Created
November 29, 2015 05:20
-
-
Save anonymous/0838392ab4b6f943e7ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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