Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249335
Change subject: PSquare: keep a count of observations
......................................................................
PSquare: keep a count of observations
Implement a PSquare::getCount() method for getting the number of observations
that have been accumulated.
Change-Id: I9dd894586e581c9e1ff764d98eda953bccc602a1
---
M src/PSquare.php
M tests/PSquareTest.php
2 files changed, 13 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/RunningStat refs/changes/35/249335/1
diff --git a/src/PSquare.php b/src/PSquare.php
index 98b089e..15e9a4a 100644
--- a/src/PSquare.php
+++ b/src/PSquare.php
@@ -63,6 +63,15 @@
}
/**
+ * Get the total number of accumulated observations.
+ *
+ * @return int
+ */
+ public function getCount() {
+ return $this->numObservations;
+ }
+
+ /**
* Add an observation.
*
* @param int|float $x Value to add
diff --git a/tests/PSquareTest.php b/tests/PSquareTest.php
index 80be45e..5eee20b 100644
--- a/tests/PSquareTest.php
+++ b/tests/PSquareTest.php
@@ -122,6 +122,8 @@
$this->assertEquals( array( 0.02, 0.5, 4.44, 17.22, 38.62 ),
$ps->heights, '', 0.1 );
$this->assertEquals( 4.4406347, $ps->getValue(), '', 0.1 );
+
+ $this->assertEquals( 20, $ps->getCount() );
}
/**
@@ -136,11 +138,13 @@
$ps->addObservation( 1 );
// Simple median of an odd number of observations.
+ $this->assertEquals( 3, $ps->getCount() );
$this->assertEquals( 5, $ps->getValue() );
$ps->addObservation( 20 );
// Simple median of an even number of observations.
+ $this->assertEquals( 4, $ps->getCount() );
$this->assertEquals( 7.5, $ps->getValue() );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/249335
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9dd894586e581c9e1ff764d98eda953bccc602a1
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