mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-24 22:07:33 +00:00
test abstraction from LayeredNetwork
This commit is contained in:
parent
ddb3cc367b
commit
64859f263f
53
tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php
Normal file
53
tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace tests\Phpml\NeuralNetwork\Network;
|
||||||
|
|
||||||
|
use Phpml\NeuralNetwork\Layer;
|
||||||
|
use Phpml\NeuralNetwork\Network\LayeredNetwork;
|
||||||
|
use Phpml\NeuralNetwork\Node\Input;
|
||||||
|
|
||||||
|
class LayeredNetworkTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testLayersSettersAndGetters()
|
||||||
|
{
|
||||||
|
$network = $this->getLayeredNetworkMock();
|
||||||
|
|
||||||
|
$network->addLayer($layer1 = new Layer());
|
||||||
|
$network->addLayer($layer2 = new Layer());
|
||||||
|
|
||||||
|
$this->assertEquals([$layer1, $layer2], $network->getLayers());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetLastLayerAsOutputLayer()
|
||||||
|
{
|
||||||
|
$network = $this->getLayeredNetworkMock();
|
||||||
|
$network->addLayer($layer1 = new Layer());
|
||||||
|
|
||||||
|
$this->assertEquals($layer1, $network->getOutputLayer());
|
||||||
|
|
||||||
|
$network->addLayer($layer2 = new Layer());
|
||||||
|
$this->assertEquals($layer2, $network->getOutputLayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetInputAndGetOutput()
|
||||||
|
{
|
||||||
|
$network = $this->getLayeredNetworkMock();
|
||||||
|
$network->addLayer(new Layer(2, Input::class));
|
||||||
|
|
||||||
|
$network->setInput($input = [34, 43]);
|
||||||
|
$this->assertEquals($input, $network->getOutput());
|
||||||
|
|
||||||
|
$network->addLayer(new Layer(1));
|
||||||
|
$this->assertEquals([0.5], $network->getOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LayeredNetwork
|
||||||
|
*/
|
||||||
|
private function getLayeredNetworkMock()
|
||||||
|
{
|
||||||
|
return $this->getMockForAbstractClass(LayeredNetwork::class);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user