Skip to content

Commit

Permalink
create phpunit configuration and first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Apr 4, 2016
1 parent ce1653a commit dd927ef
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"": "src/"
}
},
"config": {
"bin-dir": "bin"
},
Expand Down
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
beStrictAboutChangesToGlobalState="true"
>
<testsuites>
<testsuite name="PHP-ML Test Suite">
<directory>tests/*</directory>
</testsuite>
</testsuites>​
</phpunit>
4 changes: 2 additions & 2 deletions src/Phpml/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class InvalidArgumentException extends \Exception
/**
* @return InvalidArgumentException
*/
public static function parametersSizeNotMatch()
public static function sizeNotMatch()
{
return new self('Size of parameters not match');
return new self('Size of given arguments not match');
}

}
4 changes: 2 additions & 2 deletions src/Phpml/Metric/Distance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class Distance
*
* @throws InvalidArgumentException
*/
public static function euclidean(array $a, array $b): float
public static function euclidean(array $a, array $b): float
{
if(count($a) != count($b))
{
throw InvalidArgumentException::parametersSizeNotMatch();
throw InvalidArgumentException::sizeNotMatch();
}

$distance = 0;
Expand Down
18 changes: 18 additions & 0 deletions tests/Phpml/Metric/DistanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types = 1);

namespace tests\Phpml\Metric;

use Phpml\Metric\Distance;

class DistanceTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Phpml\Exception\InvalidArgumentException
*/
public function testThrowExceptionOnInvalidArguments()
{
Distance::euclidean([0, 1, 2], [0, 2]);
}

}

0 comments on commit dd927ef

Please sign in to comment.