2017-02-02 09:03:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-01-06 13:09:33 +01:00
|
|
|
namespace Phpml\Tests;
|
2017-02-02 09:03:09 +01:00
|
|
|
|
2017-11-28 08:00:13 +01:00
|
|
|
use Phpml\Exception\FileException;
|
2017-02-02 09:03:09 +01:00
|
|
|
use Phpml\ModelManager;
|
|
|
|
use Phpml\Regression\LeastSquares;
|
2017-02-03 12:58:25 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-02-02 09:03:09 +01:00
|
|
|
|
2017-02-03 12:58:25 +01:00
|
|
|
class ModelManagerTest extends TestCase
|
2017-02-02 09:03:09 +01:00
|
|
|
{
|
2017-11-14 21:21:23 +01:00
|
|
|
public function testSaveAndRestore(): void
|
2017-02-02 09:03:09 +01:00
|
|
|
{
|
2017-02-03 17:48:15 +01:00
|
|
|
$filename = uniqid();
|
2017-08-17 08:50:37 +02:00
|
|
|
$filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename;
|
2017-02-02 09:03:09 +01:00
|
|
|
|
2017-02-03 17:48:15 +01:00
|
|
|
$estimator = new LeastSquares();
|
2017-02-02 09:03:09 +01:00
|
|
|
$modelManager = new ModelManager();
|
2017-02-03 17:48:15 +01:00
|
|
|
$modelManager->saveToFile($estimator, $filepath);
|
2017-02-02 09:03:09 +01:00
|
|
|
|
|
|
|
$restored = $modelManager->restoreFromFile($filepath);
|
2017-02-03 17:48:15 +01:00
|
|
|
$this->assertEquals($estimator, $restored);
|
2017-02-02 09:03:09 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 21:21:23 +01:00
|
|
|
public function testRestoreWrongFile(): void
|
2017-02-02 09:03:09 +01:00
|
|
|
{
|
2017-11-28 08:00:13 +01:00
|
|
|
$this->expectException(FileException::class);
|
2017-08-17 08:50:37 +02:00
|
|
|
$filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'unexisting';
|
2017-02-02 09:03:09 +01:00
|
|
|
$modelManager = new ModelManager();
|
|
|
|
$modelManager->restoreFromFile($filepath);
|
|
|
|
}
|
|
|
|
}
|