From 92466d93e458c0f4821ed4e74964fda4cf918c33 Mon Sep 17 00:00:00 2001 From: Jordan LeDoux Date: Sun, 27 Jun 2021 01:45:59 -0700 Subject: [PATCH] Added the selectScale() method to number collections. --- .gitignore | 2 +- src/Samsara/Fermat/Types/NumberCollection.php | 13 ++++++++ .../Fermat/Types/NumberCollection2Test.php | 21 +++++++++++++ .../Fermat/Types/NumberCollectionTest.php | 31 ++++++++++++++++++- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests-with-modules/Samsara/Fermat/Types/NumberCollection2Test.php diff --git a/.gitignore b/.gitignore index 55bb28cb..71ccfd1c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ vendor/ composer.lock build -other +.phpunit.result.cache \ No newline at end of file diff --git a/src/Samsara/Fermat/Types/NumberCollection.php b/src/Samsara/Fermat/Types/NumberCollection.php index fc7bb1c8..dc6a5004 100644 --- a/src/Samsara/Fermat/Types/NumberCollection.php +++ b/src/Samsara/Fermat/Types/NumberCollection.php @@ -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 * diff --git a/tests-with-modules/Samsara/Fermat/Types/NumberCollection2Test.php b/tests-with-modules/Samsara/Fermat/Types/NumberCollection2Test.php new file mode 100644 index 00000000..00159390 --- /dev/null +++ b/tests-with-modules/Samsara/Fermat/Types/NumberCollection2Test.php @@ -0,0 +1,21 @@ +makeNormalDistribution(); + + $this->assertEquals('0.6726', $normal->percentAboveX(2)->truncate(4)->getValue()); + + } + +} \ No newline at end of file diff --git a/tests/Samsara/Fermat/Types/NumberCollectionTest.php b/tests/Samsara/Fermat/Types/NumberCollectionTest.php index 72d6bd46..fec48ebe 100644 --- a/tests/Samsara/Fermat/Types/NumberCollectionTest.php +++ b/tests/Samsara/Fermat/Types/NumberCollectionTest.php @@ -122,7 +122,7 @@ public function testArithmetic() } - public function testDistributions() + public function testDistributions1() { $collection = new NumberCollection([1, 2, 3, 4]); @@ -130,9 +130,25 @@ public function testDistributions() $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(); @@ -140,4 +156,17 @@ public function testDistributions() } + public function testSelectScale() + { + + $collection = new NumberCollection([ + '0.4444444444444', + new ImmutableDecimal(1, 15), + '1' + ]); + + $this->assertEquals(15, $collection->selectScale()); + + } + } \ No newline at end of file