php-ml/tests/ModelManagerTest.php

35 lines
939 B
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Phpml\Tests;
use Phpml\Exception\FileException;
use Phpml\ModelManager;
use Phpml\Regression\LeastSquares;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
2017-02-03 11:58:25 +00:00
class ModelManagerTest extends TestCase
{
public function testSaveAndRestore(): void
{
2018-10-28 06:44:52 +00:00
$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);
2018-10-28 06:44:52 +00:00
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);
}
}