mirror of https://github.com/sbt/sbt.git
Fix implementation of Relation.size.
Nothing was actually using it yet, fortunately.
This commit is contained in:
parent
9fefc18e2d
commit
57f87fe6c1
|
|
@ -118,7 +118,7 @@ private final class MRelation[A,B](fwd: Map[A, Set[B]], rev: Map[B, Set[A]]) ext
|
|||
def _1s = fwd.keySet
|
||||
def _2s = rev.keySet
|
||||
|
||||
def size = fwd.size
|
||||
def size = (fwd.valuesIterator map { _.size }).foldLeft(0)(_ + _)
|
||||
|
||||
def all: Traversable[(A,B)] = fwd.iterator.flatMap { case (a, bs) => bs.iterator.map( b => (a,b) ) }.toTraversable
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,13 @@ object RelationTest extends Properties("Relation")
|
|||
}
|
||||
}
|
||||
|
||||
property("Computes size correctly") = forAll { (entries: List[(Int, Double)]) =>
|
||||
val rel = Relation.empty[Int, Double] ++ entries
|
||||
val expected = rel.all.size // Note: not entries.length, as entries may have duplicates.
|
||||
val computed = rel.size
|
||||
"Expected size: %d. Computed size: %d.".format(expected, computed) |: expected == computed
|
||||
}
|
||||
|
||||
def all[T](s: Seq[T])(p: T => Prop): Prop =
|
||||
if(s.isEmpty) true else s.map(p).reduceLeft(_ && _)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue