You are here

public function TimeEfficientImplementationTest::testCommonSubsequence in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/sebastian/diff/tests/LCS/TimeEfficientImplementationTest.php \SebastianBergmann\Diff\LCS\TimeEfficientImplementationTest::testCommonSubsequence()

File

vendor/sebastian/diff/tests/LCS/TimeEfficientImplementationTest.php, line 102

Class

TimeEfficientImplementationTest
Some of these tests are volontary stressfull, in order to give some approximative benchmark hints.

Namespace

SebastianBergmann\Diff\LCS

Code

public function testCommonSubsequence() {
  $from = array(
    'A',
    'C',
    'E',
    'F',
    'G',
  );
  $to = array(
    'A',
    'B',
    'D',
    'E',
    'H',
  );
  $expected = array(
    'A',
    'E',
  );
  $common = $this->implementation
    ->calculate($from, $to);
  $this
    ->assertEquals($expected, $common);
  $from = array(
    'A',
    'C',
    'E',
    'F',
    'G',
  );
  $to = array(
    'B',
    'C',
    'D',
    'E',
    'F',
    'H',
  );
  $expected = array(
    'C',
    'E',
    'F',
  );
  $common = $this->implementation
    ->calculate($from, $to);
  $this
    ->assertEquals($expected, $common);
  foreach ($this->stress_sizes as $size) {
    $from = $size < 2 ? array(
      1,
    ) : range(1, $size + 1, 2);
    $to = $size < 3 ? array(
      1,
    ) : range(1, $size + 1, 3);
    $expected = $size < 6 ? array(
      1,
    ) : range(1, $size + 1, 6);
    $common = $this->implementation
      ->calculate($from, $to);
    $this
      ->assertEquals($expected, $common);
  }
}