-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated random number generation. Added example usages.
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
include 'vendor/autoload.php'; | ||
|
||
$br = PHP_EOL; | ||
if(PHP_SAPI != 'cli') { | ||
echo '<html><body><pre>'; | ||
} | ||
|
||
$time_start = microtime(true); | ||
|
||
echo "{$br}Random code generation $br"; | ||
echo "======================================================== $br"; | ||
|
||
echo "Create some random codes $br"; | ||
echo "-------------------------------------------------------- $br"; | ||
for($i = 0; $i < 5; $i++) { | ||
echo "Code $i : ". ShortCode\Random::get(). $br; | ||
} | ||
|
||
echo "{$br}Create random codes of 4 characters $br"; | ||
echo "-------------------------------------------------------- $br"; | ||
for($i = 0; $i < 5; $i++) { | ||
echo "Code $i : ". ShortCode\Random::get(4). $br; | ||
} | ||
|
||
echo "{$br}Create random codes of 6 characters, with small letter only alpha-numaric $br"; | ||
echo "-------------------------------------------------------- $br"; | ||
for($i = 0; $i < 5; $i++) { | ||
echo "Code $i : ". ShortCode\Random::get(4, \ShortCode\Code::FORMAT_ALNUM_SMALL). $br; | ||
} | ||
|
||
echo "{$br}Create random codes of 10 characters, with capital letter only $br"; | ||
echo "-------------------------------------------------------- $br"; | ||
for($i = 0; $i < 5; $i++) { | ||
echo "Code $i : ". ShortCode\Random::get(10, \ShortCode\Code::FORMAT_CHAR_CAPITAL). $br; | ||
} | ||
|
||
echo "{$br}Create random codes of 4 characters, numbers only $br"; | ||
echo "-------------------------------------------------------- $br"; | ||
for($i = 0; $i < 5; $i++) { | ||
echo "Code $i : ". ShortCode\Random::get(4, \ShortCode\Code::FORMAT_NUMBER). $br; | ||
} | ||
|
||
echo "{$br}Reversible code generation and reverting $br"; | ||
echo "======================================================== $br"; | ||
|
||
$number = 54382982; | ||
$alnum = \ShortCode\Reversible::convert($number); | ||
echo "{$br}Converting $number to alphanumeric code : $alnum {$br}"; | ||
echo "Reverting $alnum back to number : ". \ShortCode\Reversible::revert($alnum); | ||
|
||
$number = 54382982; | ||
$alnumCapital = \ShortCode\Reversible::convert($number, \ShortCode\Code::FORMAT_ALNUM_CAPITAL); | ||
echo "{$br}{$br}Converting $number to (capital letter only) alphanumeric code : $alnumCapital {$br}"; | ||
echo "Reverting $alnumCapital back to number : ". \ShortCode\Reversible::revert($alnumCapital, \ShortCode\Code::FORMAT_ALNUM_CAPITAL); | ||
|
||
$number = 54382982; | ||
$smallChars = \ShortCode\Reversible::convert($number, \ShortCode\Code::FORMAT_CHAR_SMALL); | ||
echo "{$br}{$br}Converting $number to small letter only code : $smallChars {$br}"; | ||
echo "Reverting $smallChars back to number : ". \ShortCode\Reversible::revert($smallChars, \ShortCode\Code::FORMAT_CHAR_SMALL); | ||
|
||
$time_end = microtime(true); | ||
$time = $time_end - $time_start; | ||
|
||
echo "{$br}{$br}Total time taken : $time seconds. $br"; | ||
|
||
if(PHP_SAPI != 'cli') { | ||
echo '</pre></body></html>'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="vendor/autoload.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="ShortCode Test Suite"> | ||
<directory>tests/ShortCode/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<blacklist> | ||
<directory suffix=".php">vendor/</directory> | ||
</blacklist> | ||
<whitelist> | ||
<directory suffix=".php">src/ShortCode/</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<php> | ||
<ini name="date.timezone" value="UTC"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters