test fixes

This commit is contained in:
Dennis Eichhorn 2023-10-15 13:43:45 +00:00
parent ae6391ecf8
commit 513fa7bf8b
5 changed files with 20 additions and 18 deletions

View File

@ -130,22 +130,21 @@ final class MarkovChain
$prob = \mt_rand(1, 100) / 100;
$cProb = 0.0;
$found = false;
$val = null;
$new = null;
foreach (($this->data[$keyString] ?? []) as $val => $p) {
$cProb += $p;
if ($prob <= $cProb) {
$new = $val;
$found = true;
break;
}
}
// Couldn't find possible key
if (!$found) {
if ($new === null) {
$new = $orderValues[\array_rand($orderValues)];
}

View File

@ -66,11 +66,14 @@ final class GrahamScan
$c = $points[1];
/** @var array<int, array{x:int|float, y:int|float}> $subpoints */
$subpoints = \array_slice($points, 2, $count);
\usort($subpoints, function (array $a, array $b) use ($c) : bool {
return atan2($a['y'] - $c['y'], $a['x'] - $c['x']) < atan2( $b['y'] - $c['y'], $b['x'] - $c['x']);
\usort($subpoints, function (array $a, array $b) use ($c) : int {
// @todo: Might be wrong order of comparison
return \atan2($a['y'] - $c['y'], $a['x'] - $c['x']) <=> \atan2( $b['y'] - $c['y'], $b['x'] - $c['x']);
});
/** @var array<int, array{x:int|float, y:int|float}> $points */
$points = \array_merge([$points[0], $points[1]], $subpoints);
$points[0] = $points[$count];
@ -103,9 +106,9 @@ final class GrahamScan
/**
* Counterclockwise rotation
*
* @param float[] $a Vector
* @param float[] $b Vector
* @param float[] $c Vector
* @param array<x:int|float, y:int|float> $a Vector
* @param array<x:int|float, y:int|float> $b Vector
* @param array<x:int|float, y:int|float> $c Vector
*
* @return int|float
*

View File

@ -27,7 +27,7 @@ class BinarySearchTree
/**
* Root node
*
* @param null|Node
* @var null|Node
* @since 1.0.0
*/
public ?Node $root = null;
@ -62,9 +62,9 @@ class BinarySearchTree
$comparison = $this->root->compare($data);
if ($comparison > 0) {
return $this->root->left->search($data);
return $this->root->left?->search($data);
} elseif ($comparison < 0) {
return $this->root->right->search($data);
return $this->root->right?->search($data);
}
return $this->root;
@ -126,7 +126,7 @@ class BinarySearchTree
}
$top = $node->parent;
while ($top !== Null && $top->compare($node->data)) {
while ($top !== null && $top->compare($node->data)) {
$node = $top;
$top = $top->parent;
}
@ -272,7 +272,7 @@ class BinarySearchTree
return;
} else {
$temp = $this->successor($node);
$temp = $this->successor($node);
$node->key = $temp->key;
$node->data = $temp->data;

View File

@ -82,7 +82,7 @@ class Node
*/
public function __construct(string $key, mixed $data = null)
{
$this->key = $key;
$this->key = $key;
$this->data = $data;
}

View File

@ -54,7 +54,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase
$request = new HttpRequest(new HttpUri('https://httpbin.org/post'));
$request->setMethod(RequestMethod::POST);
self::assertTrue($request->setData('pdata', 'abc'));
self::assertEquals('abc', REST::request($request)->get('form')['pdata'] ?? '');
self::assertEquals('abc', REST::request($request)->getData('form')['pdata'] ?? '');
}
/**
@ -67,7 +67,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase
$request = new HttpRequest(new HttpUri('https://httpbin.org/put'));
$request->setMethod(RequestMethod::PUT);
self::assertTrue($request->setData('pdata', 'abc'));
self::assertEquals('abc', REST::request($request)->get('form')['pdata'] ?? '');
self::assertEquals('abc', REST::request($request)->getData('form')['pdata'] ?? '');
}
/**
@ -80,7 +80,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase
$request = new HttpRequest(new HttpUri('https://httpbin.org/delete'));
$request->setMethod(RequestMethod::DELETE);
self::assertTrue($request->setData('ddata', 'abc'));
self::assertEquals('abc', REST::request($request)->get('form')['ddata'] ?? '');
self::assertEquals('abc', REST::request($request)->getData('form')['ddata'] ?? '');
}
/**
@ -93,7 +93,7 @@ final class RestTest extends \PHPUnit\Framework\TestCase
$request = new HttpRequest(new HttpUri('https://httpbin.org/get'));
$request->setMethod(RequestMethod::GET);
self::assertTrue($request->setData('gdata', 'abc'));
self::assertEquals('abc', REST::request($request)->get('args')['gdata'] ?? '');
self::assertEquals('abc', REST::request($request)->getData('args')['gdata'] ?? '');
}
/**