create phpunit configuration and first tests

This commit is contained in:
Arkadiusz Kondas 2016-04-04 22:38:51 +02:00
parent ce1653a5a7
commit dd927ef981
5 changed files with 41 additions and 4 deletions

View File

@ -11,6 +11,11 @@
"email": "arkadiusz.kondas@gmail.com"
}
],
"autoload": {
"psr-4": {
"": "src/"
}
},
"config": {
"bin-dir": "bin"
},

14
phpunit.xml Normal file
View File

@ -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>

View File

@ -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');
}
}

View File

@ -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;

View File

@ -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]);
}
}