2017-02-02 08:03:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace tests;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
public function testSaveAndRestore()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Phpml\Exception\FileException
|
|
|
|
*/
|
|
|
|
public function testRestoreWrongFile()
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|