public function testGenerateLetters_SimpleCall() { $list = array(0); Random::setCallbackRandomFunction(function ($minDigit, $maxDigit) use(&$list) { return array_shift($list); }); $random = new Random(); $this->assertSame('a', $random->generateLetter()); }
public function findRandomLine() { $desired_line = null; $random = new Random(); $i = 0; foreach ($this as $line) { if ($random->generateDigit(0, $i) < 1) { $desired_line = $line; } ++$i; } $this->rewind(); return $desired_line; }
public function testGenerateAndGet_FiveCharacters() { $list = array(0, 1, 2, 3, 4); Random::setCallbackRandomFunction(function ($minDigit, $maxDigit) use(&$list) { return array_shift($list); }); $alnum = new Alnum(); $this->assertEquals('abcde', $alnum->generateAndGet(5)); }
<?php require_once dirname(__DIR__) . '/Bootstrap.php'; use Stalxed\System\Random; $random = new Random(); $actualNumber = $random->generateNumber(1, 10); $actualArray = array(1, 2, 3, 4, 5); $actualArray = $random->shuffle($actualArray); ?> <html> <head> <title>Functional testing of a class Stalxed\System\Random.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h1>Functional testing of a class Stalxed\System\Random.</h1> <h2>Function generateNumber:</h2> <p><b>Expected value:</b> random number from 1 to 10.</p> <p><b>Actual value:</b> <?php echo $actualNumber; ?> .</p> <h2>Function shuffle:</h2> <p><b>Expected value:</b> array with the values 1, 2, 3, 4, 5 in random order.</p> <p><b>Actual value:</b> <?php echo implode(', ', $actualArray); ?> .</p> </body>
public function testFindRandomLine_AllFlagsSet() { $list = array(0, 0); Random::setCallbackRandomFunction(function ($minDigit, $maxDigit) use(&$list) { return array_shift($list); }); $this->storage->createFile('some.file'); $this->storage->filePutContents('some.file', "first\n\n\nlast\n\n\n"); $file = new FileObject($this->storage->getPath('some.file')); $file->setFlags($file::DROP_NEW_LINE | $file::READ_AHEAD | $file::SKIP_EMPTY); $this->assertEquals('last', $file->findRandomLine()); }