Skip to content

Commit

Permalink
Merge pull request #94 from JordanRL/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JordanRL committed Jun 27, 2021
2 parents 79af89b + 2d96f9d commit 61234b6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
vendor/
composer.lock
build
other
.phpunit.result.cache
13 changes: 13 additions & 0 deletions src/Samsara/Fermat/Types/NumberCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public function toArray(): array
return $this->collection->toArray();
}

public function selectScale(): int
{
$scale = 0;

foreach ($this->collection as $value) {
if ($value->getScale() > $scale) {
$scale = $value->getScale();
}
}

return $scale;
}

/**
* @param NumberInterface $number
*
Expand Down
21 changes: 21 additions & 0 deletions tests-with-modules/Samsara/Fermat/Types/NumberCollection2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Samsara\Fermat\Types;

use PHPUnit\Framework\TestCase;

class NumberCollection2Test extends TestCase
{

public function testNormalDistribution()
{

$collection = new NumberCollection([1, 2, 3, 4]);

$normal = $collection->makeNormalDistribution();

$this->assertEquals('0.6726', $normal->percentAboveX(2)->truncate(4)->getValue());

}

}
31 changes: 30 additions & 1 deletion tests/Samsara/Fermat/Types/NumberCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,51 @@ public function testArithmetic()

}

public function testDistributions()
public function testDistributions1()
{

$collection = new NumberCollection([1, 2, 3, 4]);

$this->expectException(MissingPackage::class);
$collection->makeNormalDistribution();

}

public function testDistributions2()
{

$collection = new NumberCollection([1, 2, 3, 4]);

$this->expectException(MissingPackage::class);
$collection->makePoissonDistribution();

//$this->assertEquals('0.6726', $normal->percentAboveX(2)->truncate(4)->getValue());

}

public function testDistributions3()
{

$collection = new NumberCollection([1, 2, 3, 4]);

$this->expectException(MissingPackage::class);
$collection->makeExponentialDistribution();

//$this->assertEquals('0.6726', $normal->percentAboveX(2)->truncate(4)->getValue());

}

public function testSelectScale()
{

$collection = new NumberCollection([
'0.4444444444444',
new ImmutableDecimal(1, 15),
'1'
]);

$this->assertEquals(15, $collection->selectScale());

}

}

0 comments on commit 61234b6

Please sign in to comment.