1 common.test CommonValidNumberStepUnitTestCase::testNumberStepOffset()

Tests valid_number_step() with offset.

File

core/modules/simpletest/tests/common.test, line 2393
Tests for common.inc functionality.

Class

CommonValidNumberStepUnitTestCase
Tests number step validation by valid_number_step().

Code

function testNumberStepOffset() {
  // Try obvious fits.
  $this->assertTrue(valid_number_step(11.3, 10.3, 1));
  $this->assertTrue(valid_number_step(100, 10, 50));
  $this->assertTrue(valid_number_step(-100, 90 / 7, -10));
  $this->assertTrue(valid_number_step(2 / 7 + 5 / 9, 1 / 7, 5 / 9));

  // Ensure a small offset is still invalid.
  $this->assertFalse(valid_number_step(10.3, 10.3, 0.0001));
  $this->assertFalse(valid_number_step(1 / 5, 1 / 7, 1 / 11));

  // Try negative values and offsets.
  $this->assertFalse(valid_number_step(1000, 10, -5));
  $this->assertFalse(valid_number_step(-10, 4, 0));
  $this->assertFalse(valid_number_step(-10, 4, -4));
}