Advertisement
Guest User

Untitled

a guest
Jan 18th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/env raku
  2.  
  3. multi assert ( $a is raw , &op , $b is raw) {
  4. assert ($a,&op,$b),; #Be carefull leave one , before ; : here we call assert(<list of triplets>) to avoid recursion.
  5. }
  6.  
  7. multi assert(**@tests where all(@tests>>.elems) == 3) {
  8. my Str @msgs;
  9. for @tests -> ($a is raw,$op is raw, $b is raw) {
  10. my ( $x, $y ) = ( $a.VAR.name, $b.VAR.name );
  11. @msgs.push("Assertion $x " ~ &$op.name.substr(7,*-1) ~ " $y failed : $x = $a, $y = $b") unless &$op($a,$b);
  12. }
  13. if @msgs {
  14. my $message = join " ", @msgs;
  15. die $message;
  16. }
  17. }
  18. my Int $e = 1000.rand.Int;
  19. my Int $f = 1000.rand.Int;
  20. printf("Given these 2 values, x : %d, y : %d, r : %d, s : %d\n",$x,$y,$r,$s);
  21. assert $e, &[>=], $f;
  22.  
  23. my Int $x = 1000.rand.Int;
  24. my Int $y = 1000.rand.Int;
  25. my Int $r = 1000.rand.Int;
  26. my Int $s = 1000.rand.Int;
  27. printf("Given the following values, x : %d, y : %d, r : %d, s : %d\n",$x,$y,$r,$s);
  28.  
  29. assert ($x, &[>=], $y) , ($r, &[<=], $s);
  30.  
  31.  
  32. CATCH {
  33. default {
  34. say "An exception occured : " ~ $_.payload;
  35. }
  36. };
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement