forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 2 commits.
# This is the 1st commit message: Optimize BitSet#min and max for case of Ordering.Int # This is the commit message #2: Fix buggy bitset min and max implementations
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
test/scalacheck/scala/collection/immutable/BitSetProperties.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package scala.collection.immutable | ||
import org.scalacheck._ | ||
import org.scalacheck.Prop._ | ||
import org.scalacheck.Prop.BooleanOperators | ||
import Gen._ | ||
object BitSetProperties extends Properties("immutable.BitSet") { | ||
override def overrideParameters(p: Test.Parameters): Test.Parameters = | ||
p.withMinSuccessfulTests(500) | ||
.withInitialSeed(42L) | ||
// the top of the range shouldn't be too high, else we may not get enough overlap | ||
implicit val arbitraryBitSet: Arbitrary[BitSet] = Arbitrary( | ||
oneOf( | ||
const(BitSet()), | ||
oneOf(0 to 100).map(i => BitSet(i)), | ||
listOfN(200, oneOf(0 to 10000)).map(_.to(BitSet)) | ||
) | ||
) | ||
|
||
property("min") = forAll { (bs: BitSet) => | ||
bs.nonEmpty ==> (bs.min ?= bs.toList.min) | ||
} | ||
property("min reverse") = forAll { (bs: BitSet) => | ||
bs.nonEmpty ==> (bs.min(Ordering.Int.reverse) ?= bs.toList.min(Ordering.Int.reverse)) | ||
} | ||
|
||
property("max") = forAll { (bs: BitSet) => | ||
bs.nonEmpty ==> (bs.max ?= bs.toList.max) | ||
} | ||
|
||
property("max reverse") = forAll { (bs: BitSet) => | ||
bs.nonEmpty ==> (bs.max(Ordering.Int.reverse) ?= bs.toList.max(Ordering.Int.reverse)) | ||
} | ||
} |