1 common.test CommonValidNumberStepUnitTestCase::testNumberStep()

Tests valid_number_step() without offset.

File

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

Class

CommonValidNumberStepUnitTestCase
Tests number step validation by valid_number_step().

Code

function testNumberStep() {
  // Value and step equal.
  $this->assertTrue(valid_number_step(10.3, 10.3));

  // Valid integer steps.
  $this->assertTrue(valid_number_step(42, 21));
  $this->assertTrue(valid_number_step(42, 3));

  // Valid float steps.
  $this->assertTrue(valid_number_step(42, 10.5));
  $this->assertTrue(valid_number_step(1, 1 / 3));
  $this->assertTrue(valid_number_step(-100, 100 / 7));
  $this->assertTrue(valid_number_step(1000, -10));

  // Valid and very small float steps.
  $this->assertTrue(valid_number_step(1000.12345, 1e-10));
  $this->assertTrue(valid_number_step(3.9999999999999, 1e-13));

  // Invalid integer steps.
  $this->assertFalse(valid_number_step(100, 30));
  $this->assertFalse(valid_number_step(-10, 4));

  // Invalid float steps.
  $this->assertFalse(valid_number_step(6, 5 / 7));
  $this->assertFalse(valid_number_step(10.3, 10.25));

  // Step mismatches very close to beeing valid.
  $this->assertFalse(valid_number_step(70 + 9e-7, 10 + 9e-7));
  $this->assertFalse(valid_number_step(1936.5, 3e-8));
}