Test fixes

This commit is contained in:
Dennis Eichhorn 2016-08-13 14:12:31 +02:00
parent 125bc460f1
commit f599693f11
11 changed files with 23 additions and 56 deletions

View File

@ -39,7 +39,7 @@ class Localization
* @var string
* @since 1.0.0
*/
private $country = ISO3166TwoEnum::C_USA;
private $country = ISO3166TwoEnum::_USA;
/**
* Timezone.
*
@ -60,7 +60,7 @@ class Localization
* @var string
* @since 1.0.0
*/
private $currency = ISO4217Enum::C_USD;
private $currency = ISO4217Enum::_USD;
/**
* Number format.
*

View File

@ -14,7 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\Math;
namespace phpOMS\Math\Functions;
use phpOMS\Math\Number\Numbers;
@ -60,17 +60,15 @@ class Fibunacci
*/
public static function fibunacci(int $n, int $start = 1) : int
{
if ($n < 2) {
return 0;
} elseif ($n < 4) {
if ($n < 3) {
return $start;
}
$old_1 = 0;
$old_1 = $start;
$old_2 = $start;
$fib = 0;
for ($i = 4; $i < $n; $i++) {
for ($i = 2; $i < $n; $i++) {
$fib = $old_1 + $old_2;
$old_1 = $old_2;
$old_2 = $fib;

View File

@ -13,7 +13,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Geometry;
namespace phpOMS\Math\Geometry\ConvexHull;
/**
* Andrew's monotone chain convex hull algorithm class.

View File

@ -125,10 +125,10 @@ class Integer
*/
public static function greatestCommonDivisor(int $n, int $m) : int
{
while (true) {
if ($n === $m) {
return $m;
}
$n = abs($n);
$m = abs($m);
while ($n !== $m) {
if ($n > $m) {
$n -= $m;
} else {
@ -136,7 +136,7 @@ class Integer
}
}
return 1;
return $m;
}
/**
@ -154,17 +154,18 @@ class Integer
*/
public static function fermatFactor(int $value, int $limit = 1000000) : array
{
if (($value % 2) !== 0) {
if (($value % 2) === 0) {
throw new \Exception('Only odd integers are allowed');
}
$a = (int) ceil(sqrt($value));
$b2 = $a * $a - $value;
$b2 = (int) ($a * $a - $value);
$i = 1;
while (!Numbers::isSquare($b2) && $i < $limit) {
$i++;
$a += 1;
$b2 = $a * $a - $value;
$b2 = (int) ($a * $a - $value);
}
return [(int) round($a - sqrt($b2)), (int) round($a + sqrt($b2))];

View File

@ -86,36 +86,7 @@ class Numbers
*/
public static function isSquare(int $n) : bool
{
$goodMask = 0xC840C04048404040; // 0xC840C04048404040 computed below
for ($i = 0; $i < 64; ++$i) {
$goodMask |= PHP_INT_MIN >> ($i * $i);
}
// This tests if the 6 least significant bits are right.
// Moving the to be tested bit to the highest position saves us masking.
if ($goodMask << $n >= 0) {
return false;
}
$numberOfTrailingZeros = self::countTrailingZeros($n);
// Each square ends with an even number of zeros.
if (($numberOfTrailingZeros & 1) !== 0) {
return false;
}
$n >>= $numberOfTrailingZeros;
// Now x is either 0 or odd.
// In binary each odd square ends with 001.
// Postpone the sign test until now; handle zero in the branch.
if (($n & 7) != 1 | $n <= 0) {
return $n === 0;
}
// Do it in the classical way.
// The correctness is not trivial as the conversion from long to double is lossy!
$tst = (int) sqrt($n);
return $tst * $tst === $n;
return abs(((int) sqrt($n)) * ((int) sqrt($n)) - $n) < 0.001;
}
/**

View File

@ -158,7 +158,7 @@ class Prime
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function isPrime(int $n) : bool
public static function isPrime(int $n) : bool
{
$i = 2;

View File

@ -30,5 +30,4 @@ use phpOMS\Math\Shape\ShapeInterface;
*/
interface D2ShapeInterface extends ShapeInterface
{
public static function getPerimeter() : float;
}

View File

@ -88,8 +88,8 @@ class Cone implements D3ShapeInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getHeight(float $V, float $r) : float
public static function getHeightFromVolume(float $V, float $r) : float
{
return 4 * $V / (pi() * $r ** 2);
return 3 * $V / (pi() * $r ** 2);
}
}

View File

@ -28,7 +28,6 @@ use phpOMS\Math\Shape\ShapeInterface;
* @link http://orange-management.com
* @since 1.0.0
*/
interface D2ShapeInterface extends ShapeInterface
interface D3ShapeInterface extends ShapeInterface
{
public static function getVolume() : float;
}

View File

@ -28,5 +28,4 @@ namespace phpOMS\Math\Shape;
*/
interface ShapeInterface
{
public static function getSurface() : float;
}

View File

@ -81,8 +81,8 @@ class LZW implements CompressionInterface
$w = chr($compressed[0]);
$result = $w;
$count = count($compressed);
for ($i = 1; $i < $count; $i++) {
$k = $compressed[$i];
@ -97,7 +97,7 @@ class LZW implements CompressionInterface
}
$result .= $entry;
$dictionary[$dictSize++] = $w + $entry[0];
$dictionary[$dictSize++] = $w . $entry[0];
$w = $entry;
}