Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env raku
- multi assert ( $a is raw , &op , $b is raw) {
- assert ($a,&op,$b), ;
- }
- multi assert(**@tests where all(@tests>>.elems) == 3) {
- my Str @msgs;
- for @tests -> ($a is raw,$op is raw, $b is raw) {
- my ( $x, $y ) = ( $a.VAR.name, $b.VAR.name );
- @msgs.push("Assertion $x " ~ &$op.name.substr(7,*-1) ~ " $y failed : $x = $a, $y = $b") unless &$op($a,$b);
- }
- if @msgs {
- my $message = join " ", @msgs;
- die $message;
- }
- }
- my Int $e = 1000.rand.Int;
- my Int $f = 1000.rand.Int;
- printf("Given these 2 values, e : %d, f : %d\n",$e,$f);
- assert $e, &[>=], $f;
- my Int $x = 1000.rand.Int;
- my Int $y = 1000.rand.Int;
- my Int $r = 1000.rand.Int;
- my Int $s = 1000.rand.Int;
- printf("Given the following values, x : %d, y : %d, r : %d, s : %d\n",$x,$y,$r,$s);
- assert ($x, &[>=], $y) , ($r, &[<=], $s);
- CATCH {
- default {
- say "An exception occured : " ~ $_.payload;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement