php-ml/tests/Phpml/NeuralNetwork/Network/LayeredNetworkTest.php

56 lines
1.5 KiB
PHP
Raw Normal View History

2016-08-07 21:41:08 +00:00
<?php
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
2016-08-07 21:41:08 +00:00
namespace Phpml\Tests\NeuralNetwork\Network;
2016-08-07 21:41:08 +00:00
use Phpml\NeuralNetwork\Layer;
use Phpml\NeuralNetwork\Network\LayeredNetwork;
use Phpml\NeuralNetwork\Node\Input;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
2016-08-07 21:41:08 +00:00
2017-02-03 11:58:25 +00:00
class LayeredNetworkTest extends TestCase
2016-08-07 21:41:08 +00:00
{
public function testLayersSettersAndGetters(): void
2016-08-07 21:41:08 +00:00
{
$network = $this->getLayeredNetworkMock();
$network->addLayer($layer1 = new Layer());
$network->addLayer($layer2 = new Layer());
$this->assertEquals([$layer1, $layer2], $network->getLayers());
}
public function testGetLastLayerAsOutputLayer(): void
2016-08-07 21:41:08 +00:00
{
$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(): void
2016-08-07 21:41:08 +00:00
{
$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|PHPUnit_Framework_MockObject_MockObject
*/
private function getLayeredNetworkMock()
2016-08-07 21:41:08 +00:00
{
return $this->getMockForAbstractClass(LayeredNetwork::class);
}
}