php-ml/tests/Phpml/NeuralNetwork/Node/Neuron/SynapseTest.php
Tomáš Votruba 653c7c772d Upgrade to PHP 7.1 (#150)
* upgrade to PHP 7.1

* bump travis and composer to PHP 7.1

* fix tests
2017-11-14 21:21:23 +01:00

54 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace tests\Phpml\NeuralNetwork\Node\Neuron;
use Phpml\NeuralNetwork\Node\Neuron;
use Phpml\NeuralNetwork\Node\Neuron\Synapse;
use PHPUnit\Framework\TestCase;
class SynapseTest extends TestCase
{
public function testSynapseInitialization(): void
{
$node = $this->getNodeMock($nodeOutput = 0.5);
$synapse = new Synapse($node, $weight = 0.75);
$this->assertEquals($node, $synapse->getNode());
$this->assertEquals($weight, $synapse->getWeight());
$this->assertEquals($weight * $nodeOutput, $synapse->getOutput());
$synapse = new Synapse($node);
$this->assertInternalType('float', $synapse->getWeight());
}
public function testSynapseWeightChange(): void
{
$node = $this->getNodeMock();
$synapse = new Synapse($node, $weight = 0.75);
$synapse->changeWeight(1.0);
$this->assertEquals(1.75, $synapse->getWeight());
$synapse->changeWeight(-2.0);
$this->assertEquals(-0.25, $synapse->getWeight());
}
/**
* @param int $output
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getNodeMock($output = 1)
{
$node = $this->getMockBuilder(Neuron::class)->getMock();
$node->method('getOutput')->willReturn($output);
return $node;
}
}