function Generate($level) { if ($level <= 3) { $numbers = range(1, 5); $set_size = rand(3, 4); $subset_size = 2; } elseif ($level <= 6) { $numbers = range(1, 10); $set_size = rand(4, 6); $subset_size = rand(2, 3); } else { $numbers = range(1, 20); $set_size = rand(7, 10); $subset_size = rand(3, 4); } $set = $this->Set($numbers, $set_size); $subset = NumText($subset_size); // // Original exercise // $set_size = 5; // $set = [2,3,5,7,11]; // $subset = 'kettő'; $question = 'Hány darab ' . ($subset == 'kettő' ? 'két' : $subset) . 'elemű részhalmaza van ' . The($set[0]) . ' $\\{' . implode(";", $set) . '\\}$ halmaznak?'; $correct = binomial_coeff(count($set), $subset_size); $hints = $this->Hints($set_size, $subset_size); $solution = '$' . $correct . '$'; return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints); }
public function run() { $faker = Faker::create(); foreach (range(1, 50) as $index) { User::create(['github_id' => $index, 'github_url' => $faker->url(), 'city' => $faker->city(), 'name' => $faker->userName(), 'twitter_account' => $faker->userName(), 'company' => $faker->userName(), 'personal_website' => $faker->url(), 'signature' => $faker->sentence(), 'introduction' => $faker->sentence(), 'email' => $faker->email()]); } }
public function run() { $faker = Factory::create(); foreach (range(1, 10) as $index) { Category::create(['name' => $faker->firstName, 'description' => $faker->text(130), 'active' => $faker->boolean(85)]); } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); foreach (range(1, 200) as $index) { DB::table('parts')->insert(['description' => $faker->realText(100), 'cost' => $faker->randomFloat(2, 1, 1000)]); } }
protected function setUp() { if (!class_exists('Symfony\\Component\\Form\\Form')) { $this->markTestSkipped('The "Form" component is not available'); } if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) { $this->markTestSkipped('Doctrine DBAL is not available.'); } if (!class_exists('Doctrine\\Common\\Version')) { $this->markTestSkipped('Doctrine Common is not available.'); } if (!class_exists('Doctrine\\ORM\\EntityManager')) { $this->markTestSkipped('Doctrine ORM is not available.'); } $this->em = DoctrineOrmTestCase::createTestEntityManager(); parent::setUp(); $schemaTool = new SchemaTool($this->em); $classes = array($this->em->getClassMetadata(self::ENTITY_CLASS)); try { $schemaTool->dropSchema($classes); } catch (\Exception $e) { } try { $schemaTool->createSchema($classes); } catch (\Exception $e) { } $ids = range(1, 300); foreach ($ids as $id) { $name = 65 + chr($id % 57); $this->em->persist(new SingleIdentEntity($id, $name)); } $this->em->flush(); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Product::create(['product_name' => $faker->word, 'details' => $faker->paragraph, 'picture' => 'uploads/products/1default.jpg', 'min_price' => $faker->randomDigit, 'max_price' => $faker->randomDigitNotNull, 'crop_id' => 1, 'location' => $faker->country, 'expiry_date' => $faker->date('Y--m-d')]); } }
protected function configure() { $this->addOption('date_widget', DateField::CHOICE, self::$dateWidgets); $this->addOption('time_widget', TimeField::CHOICE, self::$timeWidgets); $this->addOption('type', self::DATETIME, self::$types); $this->addOption('date_pattern'); $this->addOption('with_seconds', false); $this->addOption('years', range(date('Y') - 5, date('Y') + 5)); $this->addOption('months', range(1, 12)); $this->addOption('days', range(1, 31)); $this->addOption('hours', range(0, 23)); $this->addOption('minutes', range(0, 59)); $this->addOption('seconds', range(0, 59)); $this->addOption('data_timezone', 'UTC'); $this->addOption('user_timezone', 'UTC'); $this->addOption('date_format', DateField::MEDIUM, self::$dateFormats); $this->add(new DateField('date', array('type' => DateField::RAW, 'widget' => $this->getOption('date_widget'), 'format' => $this->getOption('date_format'), 'data_timezone' => $this->getOption('user_timezone'), 'user_timezone' => $this->getOption('user_timezone'), 'years' => $this->getOption('years'), 'months' => $this->getOption('months'), 'days' => $this->getOption('days'), 'pattern' => $this->getOption('date_pattern')))); $this->add(new TimeField('time', array('type' => TimeField::RAW, 'widget' => $this->getOption('time_widget'), 'data_timezone' => $this->getOption('user_timezone'), 'user_timezone' => $this->getOption('user_timezone'), 'with_seconds' => $this->getOption('with_seconds'), 'hours' => $this->getOption('hours'), 'minutes' => $this->getOption('minutes'), 'seconds' => $this->getOption('seconds')))); if ($this->getOption('type') == self::STRING) { $this->setNormalizationTransformer(new ReversedTransformer(new DateTimeToStringTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('data_timezone'))))); } else { if ($this->getOption('type') == self::TIMESTAMP) { $this->setNormalizationTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('data_timezone'))))); } } $this->setValueTransformer(new DateTimeToArrayTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('user_timezone')))); }
/** * @param number $step the interval amount * @return ArrayIterator */ public function getIterator($step = self::DEFAULT_STEP) { if (!is_numeric($step)) { throw new InvalidArgumentException('A numeric (int, float) step value is required'); } return new ArrayIterator(range($this->start, $this->end, $step)); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Stockpackage::create([]); } }
function json_encode($data) { if (is_array($data)) { $ret = array(); // OBJECT if (array_keys($data) !== range(0, count($data) - 1)) { foreach ($data as $key => $val) { $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val); } return "{" . implode(",", $ret) . "}"; // ARRAY } else { foreach ($data as $val) { $ret[] = json_encode($val); } return "[" . implode(",", $ret) . "]"; } // BOOLEAN OR NULL } elseif (is_bool($data) || $data === null) { return $data === null ? "null" : ($data ? "true" : "false"); } elseif (is_float($data)) { return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), "."); } elseif (is_int($data)) { return $data; } // STRING return kcfinder_json_string_encode($data); }
public function testInvalidChars() { $filter = new \r8\Filter\Alpha(); $this->assertEquals("", $filter->filter('1234567890')); $this->assertEquals("", $filter->filter('!"#$%&\'()*+,-/:;<=>?@[\\]^`{|}~')); $this->assertEquals("", $filter->filter(implode("", array_map("chr", range(127, 255))))); }
protected function getProfile() { $profile = new Twig_Profiler_Profile(); $index = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::TEMPLATE); $profile->addProfile($index); $body = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::BLOCK, 'body'); $body->leave(); $index->addProfile($body); $embedded = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::TEMPLATE); $included = new Twig_Profiler_Profile('included.twig', Twig_Profiler_Profile::TEMPLATE); $embedded->addProfile($included); $index->addProfile($embedded); $included->leave(); $embedded->leave(); $macro = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::MACRO, 'foo'); $macro->leave(); $index->addProfile($macro); $embedded = clone $embedded; $index->addProfile($embedded); $a = range(1, 1000); $embedded->leave(); $profile->leave(); usleep(5000); $index->leave(); return $profile; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $newWidth = $input->getOption('size'); $inverted = filter_var($input->getOption('inverted'), FILTER_VALIDATE_BOOLEAN); $chars = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('AsciiArtAnalyzerBundle:Char')->getAllChars($inverted); $manager = new ImageManager(['driver' => 'imagick']); $image = $manager->make("files/image.jpg"); /** * @var \Imagick $imagick */ $imagick = $image->resize($newWidth, $newWidth / $image->getWidth() * $image->getHeight())->getCore(); list($width, $height) = array_values($imagick->getImageGeometry()); $ascii = []; foreach (range(1, $height) as $y) { $string = ""; foreach (range(1, $width) as $x) { $rgb = $imagick->getImagePixelColor($x, $y)->getColor(); $pixelLuminosity = intval(($rgb['r'] + $rgb['g'] + $rgb['b']) / 3); $string .= $chars[$pixelLuminosity]; } array_push($ascii, $string); } if ($input->getOption('output') == 'image') { $this->asciiToImage($ascii, $inverted); } else { echo implode("\n", $ascii); } }
function testComplexValues() { $fields = array('timestamp' => 0, 'priority' => 42, 'priorityName' => 'bar'); $f = new Simple(); $fields['message'] = 'Foo'; $line = $f->format($fields); $this->assertContains($fields['message'], $line); $fields['message'] = 10; $line = $f->format($fields); $this->assertContains($fields['message'], $line); $fields['message'] = 10.5; $line = $f->format($fields); $this->assertContains($fields['message'], $line); $fields['message'] = true; $line = $f->format($fields); $this->assertContains('1', $line); $fields['message'] = fopen('php://stdout', 'w'); $line = $f->format($fields); $this->assertContains('Resource id ', $line); fclose($fields['message']); $fields['message'] = range(1, 10); $line = $f->format($fields); $this->assertContains('array', $line); $fields['message'] = new SimpleTest_TestObject1(); $line = $f->format($fields); $this->assertContains($fields['message']->__toString(), $line); $fields['message'] = new SimpleTest_TestObject2(); $line = $f->format($fields); $this->assertContains('object', $line); }
function compile_array($options) { if (self::check($this->from_num) && self::check($this->to_num) && abs($this->from_num - $this->to_num) <= 20) { $range = range($this->from_num, $this->to_num); if ($this->exclusive) { array_pop($range); } return '[' . implode(', ', $range) . ']'; } $idt = $this->tab . TAB; $i = $options['scope']->free_variable('i'); $result = $options['scope']->free_variable('results'); $pre = "\n{$idt}{$result} = [];"; if (self::check($this->from_num) && self::check($this->to_num)) { $options['index'] = $i; $body = $this->compile_node($options); } else { $vars = "{$i} = {$this->from_c}" . ($this->to_c !== $this->to_var ? ", {$this->to_c}" : ''); $cond = "{$this->from_var} <= {$this->to_var}"; $body = "var {$vars}; {$cond} ? {$i} <{$this->equals} {$this->to_var} : {$i} >{$this->equals} {$this->to_var}; {$cond} ? {$i}++ : {$i}--"; } $post = "{ {$result}.push({$i}); }\n{$idt}return {$result};\n{$options['indent']}"; $has_args = function ($node) { return $node->contains(function ($n) { return $n instanceof yy_Literal && $n->value === 'arguments' && !$n->as_key; }); return FALSE; }; $args = ''; if ($has_args($this->from) || $has_args($this->to)) { $args = ', arguments'; } return "(function() {{$pre}\n{$idt}for ({$body}){$post}}).apply(this{$args})"; }
/** * Changes the pen of the plotter. * * @param int $pen * @return $this */ public function changePen(int $pen) { if (!in_array($pen, range(0, 6))) { throw new \InvalidArgumentException(sprintf('[%d] is not a valid Pen.', $pen)); } return $this->pushCommand(sprintf('P%d;', $pen)); }
function build_editform($item, $feedback, $cm) { global $DB, $CFG; require_once 'multichoicerated_form.php'; //get the lastposition number of the feedback_items $position = $item->position; $lastposition = $DB->count_records('feedback_item', array('feedback' => $feedback->id)); if ($position == -1) { $i_formselect_last = $lastposition + 1; $i_formselect_value = $lastposition + 1; $item->position = $lastposition + 1; } else { $i_formselect_last = $lastposition; $i_formselect_value = $item->position; } //the elements for position dropdownlist $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); $item->presentation = empty($item->presentation) ? '' : $item->presentation; $info = $this->get_info($item); $item->ignoreempty = $this->ignoreempty($item); $item->hidenoselect = $this->hidenoselect($item); //all items for dependitem $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); $commonparams = array('cmid' => $cm->id, 'id' => isset($item->id) ? $item->id : NULL, 'typ' => $item->typ, 'items' => $feedbackitems, 'feedback' => $feedback->id); //build the form $this->item_form = new feedback_multichoicerated_form('edit_item.php', array('item' => $item, 'common' => $commonparams, 'positionlist' => $positionlist, 'position' => $position, 'info' => $info)); }
/** * AES encryption * * @param string $key * @param string $data Content to be encrypted * @param bool $hex * @return string */ static function salt() { $tmp = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)); shuffle($tmp); $salt = substr(implode('', $tmp), 0, 32); return $salt; }
public function run() { $faker = Faker::create(); foreach (range(1, 500) as $index) { Photo::create(array('title' => $faker->sentence($nbwords = 5), 'image' => $faker->imageUrl($width = 640, $height = 480), 'gallery_id' => $faker->numberBetween(1, 50))); } }
public function testFirst() { $coll1 = range(2, 10); $this->assertSame(2, f\first($coll1)); $coll2 = new \ArrayObject(array('a', 'b', 'c')); $this->assertSame('a', f\first($coll2)); }
/** * Create new list from selection then mass add to newly created list */ public function testExecute() { TestingAuxLib::suLogin('admin'); X2List::model()->deleteAllByAttributes(array('name' => 'test')); $newList = new NewListFromSelection(); $addToList = new MassAddToList(); // create new list with 2 records $_POST['modelType'] = 'Contacts'; $_POST['listName'] = 'test'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['SERVER_NAME'] = 'localhost'; Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null)); $gvSelection = range(1, 2); AuxLib::debugLogR($newList->execute($gvSelection)); $getFlashes = TestingAuxLib::setPublic('NewListFromSelection', 'getFlashes'); AuxLib::debugLogR($getFlashes()); $list = X2List::model()->findByAttributes(array('name' => 'test')); $itemIds = $list->queryCommand(true)->select('id')->queryColumn(); $this->assertEquals(array(1, 2), $itemIds); // add the rest of the contacts to the newly created list unset($_POST['modelType']); unset($_POST['listName']); $_POST['listId'] = $list->id; $gvSelection = range(3, 24); $addToList->execute($gvSelection); $itemIds = $list->queryCommand(true)->select('id')->queryColumn(); $this->assertEquals(range(1, 24), $itemIds); }
public static function deleteOld($last, $limit = 10) { $dql = 'DELETE ElfChat\\Entity\\Ajax\\Queue q WHERE q.id NOT IN(:ids)'; $query = self::entityManager()->createQuery($dql); $query->setParameter('ids', range($last, $last - $limit)); return $query->getResult(); }
function get_per_answer_fields(&$mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) { // $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption); $repeated = array(); $repeated[] =& $mform->createElement('header', 'answerhdr', $label); // if ($this->editasmultichoice == 1){ $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 50)); $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeated[] =& $mform->createElement('editor', 'feedback', get_string('feedback', 'quiz'), null, $this->editoroptions); $repeatedoptions['answer']['type'] = PARAM_RAW; $repeatedoptions['fraction']['default'] = 0; $answersoption = 'answers'; $mform->setType('answer', PARAM_NOTAGS); $addrepeated = array(); $addrepeated[] =& $mform->createElement('hidden', 'tolerance'); $addrepeated[] =& $mform->createElement('hidden', 'tolerancetype', 1); $repeatedoptions['tolerance']['type'] = PARAM_NUMBER; $repeatedoptions['tolerance']['default'] = 0.01; $addrepeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9)); $repeatedoptions['correctanswerlength']['default'] = 2; $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz')); $addrepeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats); array_splice($repeated, 3, 0, $addrepeated); $repeated[1]->setLabel('...<strong>{={x}+..}</strong>...'); return $repeated; }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Version::create([]); } }
public function testToArray() { $arr = $this->collection->toArray(); foreach (range(1, 3) as $i => $num) { $this->assertEquals($arr[$i], $num); } }
public function definition() { $mform = $this->_form; $hiddenofvisible = array(question_display_options::HIDDEN => get_string('notshown', 'question'), question_display_options::VISIBLE => get_string('shown', 'question')); $mform->addElement('header', 'optionsheader', get_string('changeoptions', 'question')); $behaviours = question_engine::get_behaviour_options($this->_customdata['quba']->get_preferred_behaviour()); $mform->addElement('select', 'behaviour', get_string('howquestionsbehave', 'question'), $behaviours); $mform->addHelpButton('behaviour', 'howquestionsbehave', 'question'); $mform->addElement('text', 'maxmark', get_string('markedoutof', 'question'), array('size' => '5')); $mform->setType('maxmark', PARAM_NUMBER); if ($this->_customdata['maxvariant'] > 1) { $variants = range(1, $this->_customdata['maxvariant']); $mform->addElement('select', 'variant', get_string('questionvariant', 'question'), array_combine($variants, $variants)); } $mform->setType('maxmark', PARAM_INT); $mform->addElement('select', 'correctness', get_string('whethercorrect', 'question'), $hiddenofvisible); $marksoptions = array(question_display_options::HIDDEN => get_string('notshown', 'question'), question_display_options::MAX_ONLY => get_string('showmaxmarkonly', 'question'), question_display_options::MARK_AND_MAX => get_string('showmarkandmax', 'question')); $mform->addElement('select', 'marks', get_string('marks', 'question'), $marksoptions); $mform->addElement('select', 'markdp', get_string('decimalplacesingrades', 'question'), question_engine::get_dp_options()); $mform->addElement('select', 'feedback', get_string('specificfeedback', 'question'), $hiddenofvisible); $mform->addElement('select', 'generalfeedback', get_string('generalfeedback', 'question'), $hiddenofvisible); $mform->addElement('select', 'rightanswer', get_string('rightanswer', 'question'), $hiddenofvisible); $mform->addElement('select', 'history', get_string('responsehistory', 'question'), $hiddenofvisible); $mform->addElement('submit', 'submit', get_string('restartwiththeseoptions', 'question'), $hiddenofvisible); }
public static function partitionTwo(DataSet $wholeSet, $partitionRelation, $seed = null) { if (!is_numeric($partitionRelation) || $partitionRelation <= 0 || $partitionRelation >= 1) { throw new InvalidArgumentException(); } // mt_srand(null) === mt_srand(0) if ($seed !== null) { mt_srand($seed); } $numElements = count($wholeSet->getData()); $indexes = range(0, $numElements - 1); self::shuffle($indexes); $trainingSet = []; $trainingSetLabels = []; $testSet = []; $testSetLabels = []; $data = $wholeSet->getData(); $labels = $wholeSet->getLabels(); for ($i = 0; $i < $numElements; $i++) { $index = $indexes[$i]; if ($i < $partitionRelation * $numElements) { $trainingSet[] = $data[$index]; $trainingSetLabels[] = $labels[$index]; } else { $testSet[] = $data[$index]; $testSetLabels[] = $labels[$index]; } } $trainingDataSet = new DataSet($trainingSet, $trainingSetLabels); $testDataSet = new DataSet($testSet, $testSetLabels); return new Partition($trainingDataSet, $testDataSet); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Leaveapplication::create([]); } }
public function __construct() { $this->allowed_upper = range('A', 'Z'); $this->allowed_lower = range('a', 'z'); $this->allowed_numbers = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); $this->allowed_symbols = array('`', '!', '"', '?', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=', '{', '[', '}', ']', ':', ';', '@', '~', '#', '|', '<', ',', '>', '.', "'", "/", '\\'); }
function showControlFrame() { global $g_oSec; if (!$g_oSec->HasPerm(DCL_ENTITY_PERSONNEL, DCL_PERM_VIEW)) { return PrintPermissionDenied(); } if (isset($_REQUEST['multiple']) && $_REQUEST['multiple'] == 'true') { $this->oSmarty->assign('VAL_MULTIPLE', 'true'); } else { $this->oSmarty->assign('VAL_MULTIPLE', 'false'); } $this->oSmarty->assign('VAL_LETTERS', array_merge(array('All'), range('A', 'Z'))); $filterActive = ''; if (isset($_REQUEST['filterActive'])) { $filterActive = $_REQUEST['filterActive']; } $filterStartsWith = ''; if (isset($_REQUEST['filterStartsWith'])) { $filterStartsWith = $_REQUEST['filterStartsWith']; } $filterID = ''; if (isset($_REQUEST['filterID'])) { $filterID = $_REQUEST['filterID']; } $this->oSmarty->assign('VAL_FILTERACTIVE', $filterActive); $this->oSmarty->assign('VAL_FILTERSTART', $filterStartsWith); $this->oSmarty->assign('VAL_FILTERID', $filterID); SmartyDisplay($this->oSmarty, 'htmlPersonnelSelectorControl.tpl'); exit; }