1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/10042] Add mt_rand() wrapper which allows swapping $min and $max.

PHPBB3-10042
This commit is contained in:
Andreas Fischer
2011-03-05 22:16:50 +01:00
parent afae883619
commit 5ab4dc2983
2 changed files with 62 additions and 0 deletions

46
tests/random/mt_rand.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_random_mt_rand_test extends phpbb_test_case
{
public function test_max_equals_min()
{
$result = phpbb_mt_rand(42, 42);
$this->assertEquals(42, $result);
}
public function test_max_equals_min_negative()
{
$result = phpbb_mt_rand(-42, -42);
$this->assertEquals(-42, $result);
}
public function test_max_greater_min()
{
$result = phpbb_mt_rand(3, 4);
$this->assertGreaterThanOrEqual(3, $result);
$this->assertLessThanOrEqual(4, $result);
}
public function test_min_greater_max()
{
$result = phpbb_mt_rand(4, 3);
$this->assertGreaterThanOrEqual(3, $result);
$this->assertLessThanOrEqual(4, $result);
}
public function test_min_greater_max_negative()
{
$result = phpbb_mt_rand(-3, -4);
$this->assertGreaterThanOrEqual(-4, $result);
$this->assertLessThanOrEqual(-3, $result);
}
}