mirror of
https://github.com/furyfire/trueskill.git
synced 2025-01-15 17:37:39 +00:00
This commit is contained in:
@ -15,4 +15,18 @@ class BasicMathTest extends TestCase
|
|||||||
$this->assertEquals(1.44, BasicMath::square(1.2));
|
$this->assertEquals(1.44, BasicMath::square(1.2));
|
||||||
$this->assertEquals(4, BasicMath::square(2));
|
$this->assertEquals(4, BasicMath::square(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSum(): void
|
||||||
|
{
|
||||||
|
$arr = [1, 1, 1, 1];
|
||||||
|
|
||||||
|
$func_return = function ($f) {
|
||||||
|
return $f;
|
||||||
|
};
|
||||||
|
$func_double = function ($f) {
|
||||||
|
return $f * 2;
|
||||||
|
};
|
||||||
|
$this->assertEquals(4, BasicMath::sum($arr, $func_return));
|
||||||
|
$this->assertEquals(8, BasicMath::sum($arr, $func_double));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,27 @@ namespace DNW\Skills\Tests\Numerics;
|
|||||||
use DNW\Skills\Numerics\IdentityMatrix;
|
use DNW\Skills\Numerics\IdentityMatrix;
|
||||||
use DNW\Skills\Numerics\Matrix;
|
use DNW\Skills\Numerics\Matrix;
|
||||||
use DNW\Skills\Numerics\SquareMatrix;
|
use DNW\Skills\Numerics\SquareMatrix;
|
||||||
|
use DNW\Skills\Numerics\DiagonalMatrix;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
#[CoversClass(Matrix::class)]
|
||||||
|
#[UsesClass(SquareMatrix::class)]
|
||||||
|
#[UsesClass(IdentityMatrix::class)]
|
||||||
|
#[UsesClass(DiagonalMatrix::class)]
|
||||||
// phpcs:disable PSR2.Methods.FunctionCallSignature,Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma
|
// phpcs:disable PSR2.Methods.FunctionCallSignature,Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma
|
||||||
class MatrixTest extends TestCase
|
class MatrixTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public function testOneByOneDeterminant(): void
|
||||||
|
{
|
||||||
|
$a = new SquareMatrix(1);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $a->getDeterminant());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testTwoByTwoDeterminant(): void
|
public function testTwoByTwoDeterminant(): void
|
||||||
{
|
{
|
||||||
$a = new SquareMatrix(1, 2,
|
$a = new SquareMatrix(1, 2,
|
||||||
@ -110,9 +125,7 @@ class MatrixTest extends TestCase
|
|||||||
1, 2, 3,
|
1, 2, 3,
|
||||||
4, 5, 6);
|
4, 5, 6);
|
||||||
|
|
||||||
$d = Matrix::fromRowsColumns(2, 3,
|
$d = Matrix::fromColumnValues(2, 3, [[1, 4], [2, 5], [3,6]]);
|
||||||
1, 2, 3,
|
|
||||||
4, 5, 6);
|
|
||||||
|
|
||||||
$this->assertTrue($c->equals($d));
|
$this->assertTrue($c->equals($d));
|
||||||
|
|
||||||
@ -144,6 +157,21 @@ class MatrixTest extends TestCase
|
|||||||
$this->assertFalse($k->equals($l));
|
$this->assertFalse($k->equals($l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAdd(): void
|
||||||
|
{
|
||||||
|
// From Wikipedia: http://en.wikipedia.org/wiki/Adjugate_matrix
|
||||||
|
$a = new SquareMatrix(1, 2,
|
||||||
|
3, 4);
|
||||||
|
|
||||||
|
$b = new SquareMatrix(4, 3,
|
||||||
|
2, 1);
|
||||||
|
|
||||||
|
$sum = Matrix::add($a, $b);
|
||||||
|
|
||||||
|
$result = new SquareMatrix(5, 5, 5, 5);
|
||||||
|
$this->assertEquals(TRUE, $result->equals($sum));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAdjugate(): void
|
public function testAdjugate(): void
|
||||||
{
|
{
|
||||||
// From Wikipedia: http://en.wikipedia.org/wiki/Adjugate_matrix
|
// From Wikipedia: http://en.wikipedia.org/wiki/Adjugate_matrix
|
||||||
@ -197,6 +225,14 @@ class MatrixTest extends TestCase
|
|||||||
|
|
||||||
$ccInverse = Matrix::multiply($c, $cInverse);
|
$ccInverse = Matrix::multiply($c, $cInverse);
|
||||||
$this->assertTrue($identity3x3->equals($ccInverse));
|
$this->assertTrue($identity3x3->equals($ccInverse));
|
||||||
|
|
||||||
|
|
||||||
|
$e = new SquareMatrix(10);
|
||||||
|
|
||||||
|
$f = new SquareMatrix(0.1);
|
||||||
|
|
||||||
|
$eInverse = $e->getInverse();
|
||||||
|
$this->assertTrue($f->equals($eInverse));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrorDeterminant(): void
|
public function testErrorDeterminant(): void
|
||||||
|
@ -27,5 +27,19 @@ class RangeTest extends TestCase
|
|||||||
$range = Range::inclusive(1, 10);
|
$range = Range::inclusive(1, 10);
|
||||||
$this->assertEquals(1, $range->getMin());
|
$this->assertEquals(1, $range->getMin());
|
||||||
$this->assertEquals(10, $range->getMax());
|
$this->assertEquals(10, $range->getMax());
|
||||||
|
$this->assertEquals(FALSE, $range->isInRange(0));
|
||||||
|
$this->assertEquals(TRUE, $range->isInRange(1));
|
||||||
|
$this->assertEquals(TRUE, $range->isInRange(2));
|
||||||
|
$this->assertEquals(TRUE, $range->isInRange(9));
|
||||||
|
$this->assertEquals(TRUE, $range->isInRange(10));
|
||||||
|
$this->assertEquals(FALSE, $range->isInRange(11));
|
||||||
|
|
||||||
|
$range = Range::atLeast(20);
|
||||||
|
$this->assertEquals(20, $range->getMin());
|
||||||
|
$this->assertEquals(PHP_INT_MAX, $range->getMax());
|
||||||
|
|
||||||
|
$range = Range::exactly(5);
|
||||||
|
$this->assertEquals(5, $range->getMin());
|
||||||
|
$this->assertEquals(5, $range->getMax());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,10 @@ use PHPUnit\Framework\Attributes\CoversNothing;
|
|||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
|
|
||||||
#[CoversClass(FactorGraphTrueSkillCalculator::class)]
|
#[CoversClass(FactorGraphTrueSkillCalculator::class)]
|
||||||
|
#[UsesClass(\DNW\Skills\Numerics\Range::class)]
|
||||||
|
#[UsesClass(\DNW\Skills\PlayersRange::class)]
|
||||||
|
#[UsesClass(\DNW\Skills\SkillCalculator::class)]
|
||||||
|
#[UsesClass(\DNW\Skills\TeamsRange::class)]
|
||||||
class FactorGraphTrueSkillCalculatorTest extends TestCase
|
class FactorGraphTrueSkillCalculatorTest extends TestCase
|
||||||
{
|
{
|
||||||
#[CoversNothing]
|
#[CoversNothing]
|
||||||
|
@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\CoversNothing;
|
use PHPUnit\Framework\Attributes\CoversNothing;
|
||||||
|
|
||||||
#[CoversClass(TwoTeamTrueSkillCalculator::class)]
|
//#[CoversClass(TwoTeamTrueSkillCalculator::class)]
|
||||||
class TwoTeamTrueSkillCalculatorTest extends TestCase
|
class TwoTeamTrueSkillCalculatorTest extends TestCase
|
||||||
{
|
{
|
||||||
#[CoversNothing]
|
#[CoversNothing]
|
||||||
|
Reference in New Issue
Block a user