You are here

public function MeasurementTest::testComparison in Physical Fields 8

Tests the comparison methods.

::covers isZero ::covers equals ::covers greaterThan ::covers greaterThanOrEqual ::covers lessThan ::covers lessThanOrEqual ::covers compareTo.

File

tests/src/Unit/MeasurementTest.php, line 95

Class

MeasurementTest
Tests the measurement base class.

Namespace

Drupal\Tests\physical\Unit

Code

public function testComparison() {
  $this
    ->assertFalse($this->measurement
    ->isZero());
  $zero_measurement = new Length('0', 'm');
  $this
    ->assertTrue($zero_measurement
    ->isZero());
  $this
    ->assertTrue($this->measurement
    ->equals(new Length('10', 'm')));
  $this
    ->assertFalse($this->measurement
    ->equals(new Length('15', 'm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThan(new Length('5', 'm')));
  $this
    ->assertFalse($this->measurement
    ->greaterThan(new Length('10', 'm')));
  $this
    ->assertFalse($this->measurement
    ->greaterThan(new Length('15', 'm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThanOrEqual(new Length('5', 'm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThanOrEqual(new Length('10', 'm')));
  $this
    ->assertFalse($this->measurement
    ->greaterThanOrEqual(new Length('15', 'm')));
  $this
    ->assertTrue($this->measurement
    ->lessThan(new Length('15', 'm')));
  $this
    ->assertFalse($this->measurement
    ->lessThan(new Length('10', 'm')));
  $this
    ->assertFalse($this->measurement
    ->lessThan(new Length('5', 'm')));
  $this
    ->assertTrue($this->measurement
    ->lessThanOrEqual(new Length('15', 'm')));
  $this
    ->assertTrue($this->measurement
    ->lessThanOrEqual(new Length('10', 'm')));
  $this
    ->assertFalse($this->measurement
    ->lessThanOrEqual(new Length('5', 'm')));

  // Test mismatched units.
  $this
    ->assertTrue($this->measurement
    ->equals(new Length('1000', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThan(new Length('500', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThanOrEqual(new Length('500', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->greaterThanOrEqual(new Length('1000', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->lessThan(new Length('1500', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->lessThanOrEqual(new Length('1500', 'cm')));
  $this
    ->assertTrue($this->measurement
    ->lessThanOrEqual(new Length('1000', 'cm')));
}