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