Пример #1
0
 /**
  * Asserts the complexity for an index
  *
  * The complexity is always O(log(n)).
  *
  * @param IndexGenerator $generator Index generator
  * @param SplitCounter   $counter   Split counter in binary search
  *
  * @return float
  */
 protected function assertComplexity(IndexGenerator $generator, SplitCounter $counter)
 {
     if (\count($counter) == 0) {
         return;
     }
     $this->assertLessThan(\log($generator->getIndexLength(), 2) * 2, \count($counter));
 }
Пример #2
0
 /**
  * Tests searching
  *
  * @param IndexGenerator $generator Index generator
  *
  * @return void
  * @dataProvider provideTestSearch
  */
 public function testSearch(IndexGenerator $generator)
 {
     $index = $generator->getIndex();
     foreach ($generator->getKeys() as $key) {
         $result = $index->search($key);
         $this->assertNotNull($result, "key: {$key}, max: {$generator->getMaximum()}," . " step: {$generator->getStepSize()}" . " length: {$generator->getIndexLength()}");
         $expected = preg_quote($generator->generateData($key));
         $this->assertRegExp("/{$expected}/", $result->getData());
     }
 }
Пример #3
0
 /**
  * @dataProvider provideTestAllValidRanges
  */
 public function testAllValidRanges(IndexGenerator $generator)
 {
     $index = $generator->getIndex();
     for ($length = 0; $length <= $generator->getIndexLength(); $length++) {
         for ($min = $generator->getMinimum(); $min + $length <= $generator->getMaximum(); $min++) {
             $range = new index\Range($min, $min + $length);
             $range->setInclusive(true);
             $foundKeys = index\IteratorUtil::toKeysArray($index->searchRange($range));
             $expectedKeys = array();
             for ($key = $range->getMin(); $key <= $range->getMax(); $key++) {
                 $expectedKeys[] = $key;
             }
             $this->assertEquals($expectedKeys, $foundKeys, "failed range[{$range->getMin()}, {$range->getMax()}] for index[{$generator->getMinimum()}, {$generator->getMaximum()}]");
         }
     }
 }