Browse Source

Make range() inclusive.

euromark 12 years ago
parent
commit
cf1ea172df
2 changed files with 5 additions and 1 deletions
  1. 1 1
      src/Validation/Validation.php
  2. 4 0
      tests/TestCase/Validation/ValidationTest.php

+ 1 - 1
src/Validation/Validation.php

@@ -731,7 +731,7 @@ class Validation {
 			return false;
 		}
 		if (isset($lower) && isset($upper)) {
-			return ($check > $lower && $check < $upper);
+			return ($check >= $lower && $check <= $upper);
 		}
 		return is_finite($check);
 	}

+ 4 - 0
tests/TestCase/Validation/ValidationTest.php

@@ -2011,6 +2011,10 @@ class ValidationTest extends TestCase {
 		$this->assertTrue(Validation::range(5));
 		$this->assertTrue(Validation::range(-5, -10, 1));
 		$this->assertFalse(Validation::range('word'));
+		$this->assertTrue(Validation::range(5.1));
+		$this->assertTrue(Validation::range(2.1, 2.1, 3.2));
+		$this->assertTrue(Validation::range(3.2, 2.1, 3.2));
+		$this->assertFalse(Validation::range(2.099, 2.1, 3.2));
 	}
 
 /**