Skip to content

Commit

Permalink
Merge pull request #447 from twitter/egonina/qtree_leq_1
Browse files Browse the repository at this point in the history
QTree quantileBounds assert percentile <= 1.0
  • Loading branch information
ianoc committed May 27, 2015
2 parents 2c9fae4 + 3bdf5f1 commit 28cbc31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -195,7 +195,7 @@ case class QTree[A](
* an estimate of the median.
*/
def quantileBounds(p: Double): (Double, Double) = {
require(p >= 0.0 && p < 1.0, "The given percentile must be of the form 0 <= p < 1.0")
require(p >= 0.0 && p <= 1.0, "The given percentile must be of the form 0 <= p <= 1.0")

val rank = math.floor(count * p).toLong
// get is safe below, because findRankLowerBound only returns
Expand Down
Expand Up @@ -79,6 +79,14 @@ class QTreeTest extends WordSpec with Matchers {
assert(truth >= lower)
assert(truth <= upper)
}
"return correct quantile bounds for two percentile extremes" in {
val list = randomList(10000)
val qt = buildQTree(k, list)
val (lower, _) = qt.quantileBounds(0.0)
val (_, upper) = qt.quantileBounds(1.0)
assert(lower == 0.0)
assert(upper == 1.0)
}
"always contain the true range sum within its bounds" in {
val list = randomList(10000)
val qt = buildQTree(k, list)
Expand Down

0 comments on commit 28cbc31

Please sign in to comment.