public function testRandomGenerator() { $stream = new StreamRandom(); $counter = new Sampler(); $counter->updateFrequencyArray($stream); $sample = $counter->produceSample(5, ' '); $values = explode(' ', $sample); $this->assertEquals(6, count($values)); }
/** * Loads all URLs to sample rendered content, per confirguration */ protected function loadURLs() { $omissions = self::config()->omit; $dataobjects = self::config()->extra_dataobjects; $i = 0; $classes = ClassInfo::subclassesFor('SiteTree'); array_shift($classes); $sampler = Sampler::create($classes)->setDefaultLimit(self::config()->default_limit)->setOmissions(self::config()->omit)->setLimits(self::config()->limits); $list = $sampler->execute(); $totalPages = $list->count(); $this->output->clearProgress(); foreach ($list as $page) { $i++; if ($html = $this->getSampleForObject($page)) { $this->samples[] = $html; } $this->output->updateProgress("{$i} / {$totalPages}"); } $this->output->writeln(); if (!empty($dataobjects)) { $this->output->clearProgress(); $i = 0; $sampler->setClasses($dataobjects); $list = $sampler->execute(); $totalPages = $list->count(); $this->output->write("Loading {$totalPages} DataObject URLs..."); foreach ($list as $object) { if (!$object->hasMethod('Link')) { $this->output->writeln("<error>{$object->ClassName} has no Link() method. Skipping.</error>"); continue; } if ($html = $this->getSampleForObject($object)) { $this->samples[] = $html; } $i++; $this->output->updateProgressPercent($i, $totalPages); } $this->output->writeln(); } }
*/ require_once __DIR__ . '/config/bootstrap.php'; $shortopts = ""; $longopts = array("stream::"); $options = getopt($shortopts, $longopts); function print_usage_exit() { echo "missing or unsupported value for argument stream usage:\n"; echo __FILE__ . " --stream=[stdin, random, randomOrg]\n"; exit; } if (!isset($options["stream"])) { print_usage_exit(); } switch ($options["stream"]) { case 'stdin': $stream = new StreamStdin(); break; case 'random': $stream = new StreamRandom(); break; case 'randomOrg': $stream = new StreamRandomOrg(); break; default: print_usage_exit(); } $sampler = new Sampler(); $sampler->updateFrequencyArray($stream); $sample = $sampler->produceSample(5); echo "a sample from the input string is [{$sample}]\n";