Skip to content

Commit

Permalink
more tests for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
winitzki committed Dec 20, 2016
1 parent bd74981 commit d8a79cd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
7 changes: 1 addition & 6 deletions lib/src/main/scala/code/winitzki/jc/JoinRun.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ import scala.collection.JavaConverters._

object JoinRun {

sealed trait InputPatternType {
def isUnconditional: Boolean = this match {
case Wildcard | SimpleVar => true
case _ => false
}
}
sealed trait InputPatternType

case object Wildcard extends InputPatternType

Expand Down
3 changes: 2 additions & 1 deletion lib/src/main/scala/code/winitzki/jc/MutableBag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MutableBag[K,V] {
anotherBag.foreach { case (k, v) => removeFromBag(k, v) }

}
/*
// about 30% slower than MutableBag, and not sure we need it, since all operations with molecule bag are synchronized now.
class ConcurrentMutableBag[K,V] {
Expand Down Expand Up @@ -123,7 +124,7 @@ class ConcurrentMutableBag[K,V] {
}
/* */
*/
// previous implementation - becomes slow if we have many repeated values, fails performance test
/*
class MutableBag[K,V] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class JoinRunBlockingSpec extends FlatSpec with Matchers with TimeLimitedTests w
it should "implement BlockingIdle(BlockingIdle()) as BlockingIdle()" in {
val tp = new SmartPool(1)
val (g, g2) = makeBlockingCheck(BlockingIdle{BlockingIdle{Thread.sleep(300)}}, tp)
g2(timeout = 50 millis)() shouldEqual Some(1) // this should not be blocked
g2(timeout = 150 millis)() shouldEqual Some(1) // this should not be blocked
tp.currentPoolSize shouldEqual 2
g() // now we know that the first reaction has finished
tp.currentPoolSize shouldEqual 1
Expand Down
7 changes: 7 additions & 0 deletions lib/src/test/scala/code/winitzki/jc/LibrarySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,11 @@ class LibrarySpec extends FlatSpec with Matchers with TimeLimitedTests {
tp.shutdownNow()
}

behavior of "cleanup with resource"

it should "catch exceptions and not fail" in {
val tryX = cleanup(1)(_ => throw new Exception("ignore this exception"))(_ => throw new Exception("foo"))
tryX.isFailure shouldEqual true
}

}
12 changes: 12 additions & 0 deletions lib/src/test/scala/code/winitzki/jc/MutableBagSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class MutableBagSpec extends FlatSpec with Matchers with TimeLimitedTests {
b.getOne(1) shouldEqual Some("a")
}

it should "make a bag with one element" in {
val b = MutableBag.of(1, "a")
b.size shouldEqual 1
b.getOne(1) shouldEqual Some("a")
}

it should "print a bag" in {
val b = MutableBag.of(1, "a")
b.addToBag(2, "b")
b.toString shouldEqual "Map(2 -> Map(b -> 1), 1 -> Map(a -> 1))"
}

it should "add two elements with the same key and the same value, them remove them both" in {
val b = new MutableBag[Int, String]
b.addToBag(1, "a")
Expand Down

0 comments on commit d8a79cd

Please sign in to comment.