mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-12-11 13:22:19 +00:00
a348111e97
* tests: update to PHPUnit 6.0 with rector * fix namespaces on tests * composer + tests: use standard test namespace naming * update travis * resolve conflict * phpstan lvl 2 * phpstan lvl 3 * phpstan lvl 4 * phpstan lvl 5 * phpstan lvl 6 * phpstan lvl 7 * level max * resolve conflict * [cs] clean empty docs * composer: bump to PHPUnit 6.4 * cleanup * composer + travis: add phpstan * phpstan lvl 1 * composer: update dev deps * phpstan fixes * update Contributing with new tools * docs: link fixes, PHP version update * composer: drop php-cs-fixer, cs already handled by ecs * ecs: add old set rules * [cs] apply rest of rules
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Tests\NeuralNetwork\Node\Neuron;
|
|
|
|
use Phpml\NeuralNetwork\Node\Neuron;
|
|
use Phpml\NeuralNetwork\Node\Neuron\Synapse;
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit_Framework_MockObject_MockObject;
|
|
|
|
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|float $output
|
|
*
|
|
* @return Neuron|PHPUnit_Framework_MockObject_MockObject
|
|
*/
|
|
private function getNodeMock($output = 1)
|
|
{
|
|
$node = $this->getMockBuilder(Neuron::class)->getMock();
|
|
$node->method('getOutput')->willReturn($output);
|
|
|
|
return $node;
|
|
}
|
|
}
|