You are here

class AuthcacheEnumCombTestCase in Authenticated User Page Caching (Authcache) 7.2

Unit tests for _authcache_enum_comb.

Hierarchy

Expanded class hierarchy of AuthcacheEnumCombTestCase

File

modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumCombTestCase.php, line 12
Defines a test case covering _authcache_enum_comb.

Namespace

Drupal\authcache_enum\Tests
View source
class AuthcacheEnumCombTestCase extends \DrupalUnitTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Combine function',
      'description' => 'Unit test for the combine function',
      'group' => 'Authcache Enum',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $module_dir = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
    require_once $module_dir . '/authcache_enum.comb.inc';
  }

  /**
   * Test calculation of k-combinations.
   */
  public function testCombineK() {
    $set = array(
      'a',
      'b',
      'c',
      'd',
    );
    $expect = array(
      array(
        'a',
      ),
      array(
        'b',
      ),
      array(
        'c',
      ),
      array(
        'd',
      ),
    );
    $result = _authcache_enum_comb_k($set, 1);
    $this
      ->assertEqual($expect, $result);
    $expect = array(
      array(
        'a',
        'b',
      ),
      array(
        'a',
        'c',
      ),
      array(
        'a',
        'd',
      ),
      array(
        'b',
        'c',
      ),
      array(
        'b',
        'd',
      ),
      array(
        'c',
        'd',
      ),
    );
    $result = _authcache_enum_comb_k($set, 2);
    $this
      ->assertEqual($expect, $result);
    $expect = array(
      array(
        'a',
        'b',
        'c',
      ),
      array(
        'a',
        'b',
        'd',
      ),
      array(
        'a',
        'c',
        'd',
      ),
      array(
        'b',
        'c',
        'd',
      ),
    );
    $result = _authcache_enum_comb_k($set, 3);
    $this
      ->assertEqual($expect, $result);
  }

  /**
   * Test calculation of k-combinations where k is out of range.
   */
  public function testCombineKOffLimit() {
    $set = array(
      'a',
      'b',
      'c',
      'd',
    );
    $expect = array(
      array(
        'a',
      ),
      array(
        'b',
      ),
      array(
        'c',
      ),
      array(
        'd',
      ),
    );
    $result = _authcache_enum_comb_k($set, 0);
    $this
      ->assertEqual($expect, $result);
    $expect = array(
      array(
        'a',
        'b',
        'c',
        'd',
      ),
    );
    $result = _authcache_enum_comb_k($set, 4);
    $this
      ->assertEqual($expect, $result);
  }

  /**
   * Test calculation of combinations.
   */
  public function testCombine() {
    $set = array(
      'a',
      'b',
      'c',
      'd',
    );
    $expect = array(
      array(
        'a',
      ),
      array(
        'b',
      ),
      array(
        'c',
      ),
      array(
        'd',
      ),
      array(
        'a',
        'b',
      ),
      array(
        'a',
        'c',
      ),
      array(
        'a',
        'd',
      ),
      array(
        'b',
        'c',
      ),
      array(
        'b',
        'd',
      ),
      array(
        'c',
        'd',
      ),
      array(
        'a',
        'b',
        'c',
      ),
      array(
        'a',
        'b',
        'd',
      ),
      array(
        'a',
        'c',
        'd',
      ),
      array(
        'b',
        'c',
        'd',
      ),
      array(
        'a',
        'b',
        'c',
        'd',
      ),
    );
    $result = _authcache_enum_comb($set);
    $this
      ->assertEqual($expect, $result);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthcacheEnumCombTestCase::getInfo public static function
AuthcacheEnumCombTestCase::setUp public function
AuthcacheEnumCombTestCase::testCombine public function Test calculation of combinations.
AuthcacheEnumCombTestCase::testCombineK public function Test calculation of k-combinations.
AuthcacheEnumCombTestCase::testCombineKOffLimit public function Test calculation of k-combinations where k is out of range.