63 / 68 lines covered (92.6%)
1unit module BDD::Behave::Matcher::Numeric;23use BDD::Behave::Matcher;45class BeGreaterThanMatcher does Matcher is export {6 has $.expected;78 method matches($actual --> Bool) {9 return False unless $actual.defined;10 return False unless $actual ~~ Real;11 ?($actual > $!expected);12 }1314 method failure-message($actual --> Str) {15 "expected " ~ $actual.raku ~ " to be greater than " ~ $!expected.raku;16 }1718 method failure-message-negated($actual --> Str) {19 "expected " ~ $actual.raku ~ " not to be greater than " ~ $!expected.raku;20 }2122 method expected-value(--> Mu) { $!expected }2324 method description(--> Str) { 'be greater than ' ~ $!expected.raku }25}2627class BeGreaterThanOrEqualMatcher does Matcher is export {28 has $.expected;2930 method matches($actual --> Bool) {31 return False unless $actual.defined;32 return False unless $actual ~~ Real;33 ?($actual >= $!expected);34 }3536 method failure-message($actual --> Str) {37 "expected " ~ $actual.raku ~ " to be greater than or equal to "38 ~ $!expected.raku;39 }4041 method failure-message-negated($actual --> Str) {42 "expected " ~ $actual.raku ~ " not to be greater than or equal to "43 ~ $!expected.raku;44 }4546 method expected-value(--> Mu) { $!expected }4748 method description(--> Str) {49 'be greater than or equal to ' ~ $!expected.raku;50 }51}5253class BeLessThanMatcher does Matcher is export {54 has $.expected;5556 method matches($actual --> Bool) {57 return False unless $actual.defined;58 return False unless $actual ~~ Real;59 ?($actual < $!expected);60 }6162 method failure-message($actual --> Str) {63 "expected " ~ $actual.raku ~ " to be less than " ~ $!expected.raku;64 }6566 method failure-message-negated($actual --> Str) {67 "expected " ~ $actual.raku ~ " not to be less than " ~ $!expected.raku;68 }6970 method expected-value(--> Mu) { $!expected }7172 method description(--> Str) { 'be less than ' ~ $!expected.raku }73}7475class BeLessThanOrEqualMatcher does Matcher is export {76 has $.expected;7778 method matches($actual --> Bool) {79 return False unless $actual.defined;80 return False unless $actual ~~ Real;81 ?($actual <= $!expected);82 }8384 method failure-message($actual --> Str) {85 "expected " ~ $actual.raku ~ " to be less than or equal to "86 ~ $!expected.raku;87 }8889 method failure-message-negated($actual --> Str) {90 "expected " ~ $actual.raku ~ " not to be less than or equal to "91 ~ $!expected.raku;92 }9394 method expected-value(--> Mu) { $!expected }9596 method description(--> Str) {97 'be less than or equal to ' ~ $!expected.raku;98 }99}100101class BeBetweenMatcher does Matcher is export {102 has $.min;103 has $.max;104 has Bool $.exclusive = False;105106 method matches($actual --> Bool) {107 return False unless $actual.defined;108 return False unless $actual ~~ Real;109 if $!exclusive {110 ?($actual > $!min && $actual < $!max);111 } else {112 ?($actual >= $!min && $actual <= $!max);113 }114 }115116 method bounds-clause(--> Str) {117 $!exclusive118 ?? $!min.raku ~ ' and ' ~ $!max.raku ~ ' (exclusive)'119 !! $!min.raku ~ ' and ' ~ $!max.raku ~ ' (inclusive)';120 }121122 method failure-message($actual --> Str) {123 "expected " ~ $actual.raku ~ " to be between " ~ self.bounds-clause;124 }125126 method failure-message-negated($actual --> Str) {127 "expected " ~ $actual.raku ~ " not to be between " ~ self.bounds-clause;128 }129130 method expected-value(--> Mu) { [$!min, $!max] }131132 method description(--> Str) { 'be between ' ~ self.bounds-clause }133}134135class BeWithinMatcher does Matcher is export {136 has $.delta;137 has $.expected;138139 method matches($actual --> Bool) {140 return False unless $actual.defined;141 return False unless $actual ~~ Real;142 return False unless $!expected.defined;143 return False unless $!expected ~~ Real;144 ?(abs($actual - $!expected) <= $!delta);145 }146147 method failure-message($actual --> Str) {148 "expected " ~ $actual.raku ~ " to be within " ~ $!delta.raku149 ~ " of " ~ $!expected.raku;150 }151152 method failure-message-negated($actual --> Str) {153 "expected " ~ $actual.raku ~ " not to be within " ~ $!delta.raku154 ~ " of " ~ $!expected.raku;155 }156157 method expected-value(--> Mu) { $!expected }158159 method description(--> Str) {160 'be within ' ~ $!delta.raku ~ ' of ' ~ $!expected.raku;161 }162}