beWithin method

NumericAssertions beWithin(
  1. num min,
  2. num max
)

Asserts that a value is within a range.

min The minimum valid value of the range. max The maximum valid value of the range.

Implementation

NumericAssertions beWithin(num min, num max) {
  if (isReversed) {
    if (subject! < max && subject! > min) {
      throw ShouldlyTestFailureError(
        '\n$subjectLabel number\n    $subject\nshould not be within\n    [$min, $max]',
      );
    }
  } else {
    if (subject! > max || subject! < min) {
      throw ShouldlyTestFailureError(
        '\n$subjectLabel number\n    $subject\nshould be within\n    [$min, $max]',
      );
    }
  }

  return NumericAssertions(subject);
}