mirror of
https://github.com/furyfire/trueskill.git
synced 2025-03-19 00:08:37 +00:00
More tests more resistance to mutation testing.
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
This commit is contained in:
@ -28,7 +28,9 @@ class GuardTest extends TestCase
|
||||
|
||||
public function testargumentIsValidIndexArgumentValid(): void
|
||||
{
|
||||
Guard::argumentIsValidIndex(5, 10, "dummy");
|
||||
Guard::argumentIsValidIndex(0, 10, "dummy");
|
||||
Guard::argumentIsValidIndex(1, 10, "dummy");
|
||||
Guard::argumentIsValidIndex(9, 10, "dummy");
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
@ -48,7 +50,12 @@ class GuardTest extends TestCase
|
||||
|
||||
public function testargumentInRangeInclusiveValid(): void
|
||||
{
|
||||
Guard::argumentInRangeInclusive(0, 0, 100, "dummy");
|
||||
Guard::argumentInRangeInclusive(1, 0, 100, "dummy");
|
||||
Guard::argumentInRangeInclusive(50, 0, 100, "dummy");
|
||||
Guard::argumentInRangeInclusive(99, 0, 100, "dummy");
|
||||
Guard::argumentInRangeInclusive(100, 0, 100, "dummy");
|
||||
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ class HashMapTest extends TestCase
|
||||
$h->setvalue($o2, 2);
|
||||
|
||||
$this->assertEquals([1, 2], $h->getAllValues());
|
||||
$this->assertEquals([$o1, $o2], $h->getAllKeys());
|
||||
|
||||
$this->assertEquals(1, $h->getvalue($o1));
|
||||
$this->assertEquals(2, $h->getvalue($o2));
|
||||
|
@ -92,6 +92,20 @@ class GaussianDistributionTest extends TestCase
|
||||
$m3s4 = new GaussianDistribution(3, 4);
|
||||
$lpn2 = GaussianDistribution::logProductNormalization($m1s2, $m3s4);
|
||||
$this->assertEqualsWithDelta(-2.5168046699816684, $lpn2, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$lrn = GaussianDistribution::logProductNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 1);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$lrn = GaussianDistribution::logProductNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 1);
|
||||
$lrn = GaussianDistribution::logProductNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
}
|
||||
|
||||
public function testLogRatioNormalization(): void
|
||||
@ -101,6 +115,20 @@ class GaussianDistributionTest extends TestCase
|
||||
$m3s4 = new GaussianDistribution(3, 4);
|
||||
$lrn = GaussianDistribution::logRatioNormalization($m1s2, $m3s4);
|
||||
$this->assertEqualsWithDelta(2.6157405972171204, $lrn, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$lrn = GaussianDistribution::logRatioNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 1);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$lrn = GaussianDistribution::logRatioNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
$numerator = GaussianDistribution::fromPrecisionMean(1, 0);
|
||||
$denominator = GaussianDistribution::fromPrecisionMean(1, 1);
|
||||
$lrn = GaussianDistribution::logRatioNormalization($numerator, $denominator);
|
||||
$this->assertEquals(0, $lrn);
|
||||
}
|
||||
|
||||
public function testAbsoluteDifference(): void
|
||||
@ -115,4 +143,27 @@ class GaussianDistributionTest extends TestCase
|
||||
$absDiff2 = GaussianDistribution::absoluteDifference($m1s2, $m3s4);
|
||||
$this->assertEqualsWithDelta(0.4330127018922193, $absDiff2, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||
}
|
||||
|
||||
public function testSubtract(): void
|
||||
{
|
||||
// Verified with Ralf Herbrich's F# implementation
|
||||
$standardNormal = new GaussianDistribution(0, 1);
|
||||
$absDiff = GaussianDistribution::subtract($standardNormal, $standardNormal);
|
||||
$this->assertEqualsWithDelta(0.0, $absDiff, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||
|
||||
$m1s2 = new GaussianDistribution(1, 2);
|
||||
$m3s4 = new GaussianDistribution(3, 4);
|
||||
$absDiff2 = GaussianDistribution::subtract($m1s2, $m3s4);
|
||||
$this->assertEqualsWithDelta(0.4330127018922193, $absDiff2, GaussianDistributionTest::ERROR_TOLERANCE);
|
||||
}
|
||||
|
||||
public function testfromPrecisionMean(): void
|
||||
{
|
||||
$gd = GaussianDistribution::fromPrecisionMean(0, 0);
|
||||
$this->assertInfinite($gd->getVariance());
|
||||
$this->assertInfinite($gd->getStandardDeviation());
|
||||
$this->assertNan($gd->getMean());
|
||||
$this->assertEquals(0, $gd->getPrecisionMean());
|
||||
$this->assertEquals(0, $gd->getPrecision());
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,83 @@ use Exception;
|
||||
// phpcs:disable PSR2.Methods.FunctionCallSignature,Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma
|
||||
class MatrixTest extends TestCase
|
||||
{
|
||||
public function testEmptyMatrix(): void
|
||||
{
|
||||
$m1 = new Matrix();
|
||||
$this->assertEquals(0, $m1->getRowCount());
|
||||
$this->assertEquals(0, $m1->getColumnCount());
|
||||
|
||||
$m2 = new Matrix(0, 0);
|
||||
$this->assertEquals(0, $m2->getRowCount());
|
||||
$this->assertEquals(0, $m2->getColumnCount());
|
||||
|
||||
$this->assertEquals(new Matrix(), Matrix::multiply($m1, $m2));
|
||||
}
|
||||
|
||||
public function testIndexing(): void
|
||||
{
|
||||
$m = new Matrix(5, 5);
|
||||
$m->setValue(0, 0, 1);
|
||||
$this->assertEquals(1, $m->getValue(0, 0));
|
||||
$m->setValue(0, 1, 2);
|
||||
$this->assertEquals(2, $m->getValue(0, 1));
|
||||
$m->setValue(1, 0, 3);
|
||||
$this->assertEquals(3, $m->getValue(1, 0));
|
||||
$m->setValue(1, 1, 4);
|
||||
$this->assertEquals(4, $m->getValue(1, 1));
|
||||
|
||||
$m->setValue(3, 3, 11);
|
||||
$this->assertEquals(11, $m->getValue(3, 3));
|
||||
$m->setValue(4, 3, 22);
|
||||
$this->assertEquals(22, $m->getValue(4, 3));
|
||||
$m->setValue(3, 4, 33);
|
||||
$this->assertEquals(33, $m->getValue(3, 4));
|
||||
$m->setValue(4, 4, 44);
|
||||
$this->assertEquals(44, $m->getValue(4, 4));
|
||||
|
||||
try {
|
||||
$m->getValue(-1, -1);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
|
||||
try {
|
||||
$m->getValue(-1, 0);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
|
||||
try {
|
||||
$m->getValue(0, -1);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
|
||||
try {
|
||||
$m->getValue(5, 5);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
|
||||
try {
|
||||
$m->getValue(5, 4);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
|
||||
try {
|
||||
$m->getValue(4, 5);
|
||||
$this->fail("No exception");
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(Exception::class, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
public function testOneByOneDeterminant(): void
|
||||
{
|
||||
$a = new SquareMatrix(1);
|
||||
|
Reference in New Issue
Block a user