Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249069
Change subject: Small code clean-ups
......................................................................
Small code clean-ups
* Make RunningStat not extend Countable. It's gimmicky and adds little value.
Add a RunningStat::getCount() method instead.
* Get rid of @covers annotations in the test suite. I don't find much value in
them and finding out I was using them incorrectly was all the motivation I
needed to stop using them entirely.
* Get rid of trailing newline in .editorconfig.
Change-Id: I0a4a4802e8d08a5afa4ddc891d98426dab0749af
---
M .editorconfig
M src/RunningStat.php
M tests/RunningStatTest.php
3 files changed, 7 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/RunningStat refs/changes/69/249069/1
diff --git a/.editorconfig b/.editorconfig
index 42aefb6..7c8c7ab 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -3,4 +3,3 @@
[*]
indent_style = tab
-
diff --git a/src/RunningStat.php b/src/RunningStat.php
index 6929447..f0affef 100644
--- a/src/RunningStat.php
+++ b/src/RunningStat.php
@@ -51,7 +51,7 @@
* English Wikipedia articles "Variance", "Algorithms for calculating
* variance", and "Standard deviation".
*/
-class RunningStat implements \Countable {
+class RunningStat {
/** @var int Number of samples. **/
public $n = 0;
@@ -70,9 +70,9 @@
/**
* Count the number of accumulated values.
- * @return int Number of values
+ * @return int
*/
- public function count() {
+ public function getCount() {
return $this->n;
}
@@ -100,7 +100,7 @@
* The arithmetic mean is the sum of all measurements divided by the
number
* of observations in the data set.
*
- * @return float Mean
+ * @return float
*/
public function getMean() {
return $this->m1;
diff --git a/tests/RunningStatTest.php b/tests/RunningStatTest.php
index de21571..0b6c6c2 100644
--- a/tests/RunningStatTest.php
+++ b/tests/RunningStatTest.php
@@ -25,9 +25,6 @@
use RunningStat\RunningStat;
-/**
- * @covers RunningStat\RunningStat
- */
class RunningStatTest extends \PHPUnit_Framework_TestCase {
public $points = array(
@@ -40,11 +37,6 @@
/**
* Verify that the statistical moments and extrema computed by
RunningStat
* match expected values.
- * @covers RunningStat::push
- * @covers RunningStat::count
- * @covers RunningStat::getMean
- * @covers RunningStat::getVariance
- * @covers RunningStat::getStdDev
*/
public function testRunningStatAccuracy() {
$rstat = new RunningStat();
@@ -55,10 +47,10 @@
$mean = array_sum( $this->points ) / count( $this->points );
$variance = array_sum( array_map( function ( $x ) use ( $mean )
{
return pow( $mean - $x, 2 );
- }, $this->points ) ) / ( count( $rstat ) - 1 );
+ }, $this->points ) ) / ( $rstat->getCount() - 1 );
$stddev = sqrt( $variance );
- $this->assertEquals( count( $rstat ), count( $this->points ) );
+ $this->assertEquals( $rstat->getCount(), count( $this->points )
);
$this->assertEquals( $rstat->min, min( $this->points ) );
$this->assertEquals( $rstat->max, max( $this->points ) );
$this->assertEquals( $rstat->getMean(), $mean );
@@ -70,8 +62,6 @@
* When one RunningStat instance is merged into another, the state of
the
* target RunningInstance should have the state that it would have had
if
* all the data had been accumulated by it alone.
- * @covers RunningStat::merge
- * @covers RunningStat::count
*/
public function testRunningStatMerge() {
$expected = new RunningStat();
@@ -98,7 +88,7 @@
// Merge the second RunningStat object into the first
$first->merge( $second );
- $this->assertEquals( count( $first ), count( $this->points ) );
+ $this->assertEquals( $first->getCount(), count( $this->points )
);
$this->assertEquals( $first, $expected );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/249069
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a4a4802e8d08a5afa4ddc891d98426dab0749af
Gerrit-PatchSet: 1
Gerrit-Project: RunningStat
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits