mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 21:15:10 +00:00
8f122fde90
* Models manager with save/restore capabilities * Refactoring dataset exceptions * Persistency layer docs * New tests for serializable estimators * ModelManager static methods to instance methods
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace tests;
|
|
|
|
use Phpml\ModelManager;
|
|
use Phpml\Regression\LeastSquares;
|
|
|
|
class ModelManagerTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
public function testSaveAndRestore()
|
|
{
|
|
$filename = 'test-save-to-file-'.rand(100, 999).'-'.uniqid();
|
|
$filepath = tempnam(sys_get_temp_dir(), $filename);
|
|
|
|
$obj = new LeastSquares();
|
|
$modelManager = new ModelManager();
|
|
$modelManager->saveToFile($obj, $filepath);
|
|
|
|
$restored = $modelManager->restoreFromFile($filepath);
|
|
$this->assertEquals($obj, $restored);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Phpml\Exception\FileException
|
|
*/
|
|
public function testSaveToWrongFile()
|
|
{
|
|
$filepath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'unexisting';
|
|
|
|
$obj = new LeastSquares();
|
|
$modelManager = new ModelManager();
|
|
$modelManager->saveToFile($obj, $filepath);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Phpml\Exception\FileException
|
|
*/
|
|
public function testRestoreWrongFile()
|
|
{
|
|
$filepath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'unexisting';
|
|
$modelManager = new ModelManager();
|
|
$modelManager->restoreFromFile($filepath);
|
|
}
|
|
}
|