mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-30 16:53:54 +00:00
35 lines
939 B
PHP
35 lines
939 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Tests;
|
|
|
|
use Phpml\Exception\FileException;
|
|
use Phpml\ModelManager;
|
|
use Phpml\Regression\LeastSquares;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ModelManagerTest extends TestCase
|
|
{
|
|
public function testSaveAndRestore(): void
|
|
{
|
|
$filename = uniqid('', false);
|
|
$filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename;
|
|
|
|
$estimator = new LeastSquares();
|
|
$modelManager = new ModelManager();
|
|
$modelManager->saveToFile($estimator, $filepath);
|
|
|
|
$restored = $modelManager->restoreFromFile($filepath);
|
|
self::assertEquals($estimator, $restored);
|
|
}
|
|
|
|
public function testRestoreWrongFile(): void
|
|
{
|
|
$this->expectException(FileException::class);
|
|
$filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'unexisting';
|
|
$modelManager = new ModelManager();
|
|
$modelManager->restoreFromFile($filepath);
|
|
}
|
|
}
|