summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/Ctrie.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-09-18 00:09:46 -0700
committerPaul Phillips <paulp@improving.org>2013-09-18 07:13:38 -0700
commitf4267ccd96a9143c910c66a5b0436aaa64b7c9dc (patch)
tree174861715807c23ba332f78769a9f7e1377b7f02 /test/files/scalacheck/Ctrie.scala
parentd45a3c8cc8e9f1d95d797d548a85abd8597f5bc7 (diff)
downloadscala-f4267ccd96a9143c910c66a5b0436aaa64b7c9dc.tar.gz
scala-f4267ccd96a9143c910c66a5b0436aaa64b7c9dc.tar.bz2
scala-f4267ccd96a9143c910c66a5b0436aaa64b7c9dc.zip
Cull extraneous whitespace.
One last flurry with the broom before I leave you slobs to code in your own filth. Eliminated all the trailing whitespace I could manage, with special prejudice reserved for the test cases which depended on the preservation of trailing whitespace. Was reminded I cannot figure out how to eliminate the trailing space on the "scala> " prompt in repl transcripts. At least reduced the number of such empty prompts by trimming transcript code on the way in. Routed ConsoleReporter's "printMessage" through a trailing whitespace stripping method which might help futureproof against the future of whitespace diseases. Deleted the up-to-40 lines of trailing whitespace found in various library files. It seems like only yesterday we performed whitespace surgery on the whole repo. Clearly it doesn't stick very well. I suggest it would work better to enforce a few requirements on the way in.
Diffstat (limited to 'test/files/scalacheck/Ctrie.scala')
-rw-r--r--test/files/scalacheck/Ctrie.scala66
1 files changed, 33 insertions, 33 deletions
diff --git a/test/files/scalacheck/Ctrie.scala b/test/files/scalacheck/Ctrie.scala
index 736bf938bc..714f1c3b09 100644
--- a/test/files/scalacheck/Ctrie.scala
+++ b/test/files/scalacheck/Ctrie.scala
@@ -17,21 +17,21 @@ case class Wrap(i: Int) {
/** A check mainly oriented towards checking snapshot correctness.
*/
object Test extends Properties("concurrent.TrieMap") {
-
+
/* generators */
-
+
val sizes = choose(0, 200000)
-
+
val threadCounts = choose(2, 16)
-
+
val threadCountsAndSizes = for {
p <- threadCounts
sz <- sizes
} yield (p, sz);
-
-
+
+
/* helpers */
-
+
def inParallel[T](totalThreads: Int)(body: Int => T): Seq[T] = {
val threads = for (idx <- 0 until totalThreads) yield new Thread {
setName("ParThread-" + idx)
@@ -44,11 +44,11 @@ object Test extends Properties("concurrent.TrieMap") {
res
}
}
-
+
threads foreach (_.start())
threads map (_.result)
}
-
+
def spawn[T](body: =>T): { def get: T } = {
val t = new Thread {
setName("SpawnThread")
@@ -66,7 +66,7 @@ object Test extends Properties("concurrent.TrieMap") {
}
}
}
-
+
def elementRange(threadIdx: Int, totalThreads: Int, totalElems: Int): Range = {
val sz = totalElems
val idx = threadIdx
@@ -76,7 +76,7 @@ object Test extends Properties("concurrent.TrieMap") {
val end = start + elems
(start until end)
}
-
+
def hasGrown[K, V](last: Map[K, V], current: Map[K, V]) = {
(last.size <= current.size) && {
last forall {
@@ -84,7 +84,7 @@ object Test extends Properties("concurrent.TrieMap") {
}
}
}
-
+
object err {
var buffer = new StringBuilder
def println(a: AnyRef) = buffer.append(a.toString).append("\n")
@@ -94,16 +94,16 @@ object Test extends Properties("concurrent.TrieMap") {
clear()
}
}
-
-
+
+
/* properties */
-
+
property("concurrent growing snapshots") = forAll(threadCounts, sizes) {
(numThreads, numElems) =>
val p = 3 //numThreads
val sz = 102 //numElems
val ct = new TrieMap[Wrap, Int]
-
+
// checker
val checker = spawn {
def check(last: Map[Wrap, Int], iterationsLeft: Int): Boolean = {
@@ -115,23 +115,23 @@ object Test extends Properties("concurrent.TrieMap") {
}
check(ct.readOnlySnapshot(), 500)
}
-
+
// fillers
inParallel(p) {
idx =>
elementRange(idx, p, sz) foreach (i => ct.update(Wrap(i), i))
}
-
+
// wait for checker to finish
val growing = true//checker.get
-
+
val ok = growing && ((0 until sz) forall {
case i => ct.get(Wrap(i)) == Some(i)
})
-
+
ok
}
-
+
property("update") = forAll(sizes) {
(n: Int) =>
val ct = new TrieMap[Int, Int]
@@ -140,52 +140,52 @@ object Test extends Properties("concurrent.TrieMap") {
case i => ct(i) == i
}
}
-
+
property("concurrent update") = forAll(threadCountsAndSizes) {
case (p, sz) =>
val ct = new TrieMap[Wrap, Int]
-
+
inParallel(p) {
idx =>
for (i <- elementRange(idx, p, sz)) ct(Wrap(i)) = i
}
-
+
(0 until sz) forall {
case i => ct(Wrap(i)) == i
}
}
-
-
+
+
property("concurrent remove") = forAll(threadCounts, sizes) {
(p, sz) =>
val ct = new TrieMap[Wrap, Int]
for (i <- 0 until sz) ct(Wrap(i)) = i
-
+
inParallel(p) {
idx =>
for (i <- elementRange(idx, p, sz)) ct.remove(Wrap(i))
}
-
+
(0 until sz) forall {
case i => ct.get(Wrap(i)) == None
}
}
-
-
+
+
property("concurrent putIfAbsent") = forAll(threadCounts, sizes) {
(p, sz) =>
val ct = new TrieMap[Wrap, Int]
-
+
val results = inParallel(p) {
idx =>
elementRange(idx, p, sz) find (i => ct.putIfAbsent(Wrap(i), i) != None)
}
-
+
(results forall (_ == None)) && ((0 until sz) forall {
case i => ct.get(Wrap(i)) == Some(i)
})
}
-
+
}