diff --git a/main/src/test/scala/TagsTest.scala b/main/src/test/scala/TagsTest.scala index 85be939b2..e4edf131a 100644 --- a/main/src/test/scala/TagsTest.scala +++ b/main/src/test/scala/TagsTest.scala @@ -2,27 +2,36 @@ package sbt import org.scalacheck._ import Gen.{listOf} -import Prop.forAll +import Prop._ import Tags._ object TagsTest extends Properties("Tags") { + final case class Size(value: Int) + def tagMap: Gen[TagMap] = for(ts <- listOf(tagAndFrequency)) yield ts.toMap def tagAndFrequency: Gen[(Tag, Int)] = for(t <- tag; count <- Arbitrary.arbitrary[Int]) yield (t, count) - def tag: Gen[Tag] = for(s <- Arbitrary.arbitrary[String]) yield Tag(s) + def tag: Gen[Tag] = for(s <- Gen.alphaStr if !s.isEmpty) yield Tag(s) + def size: Gen[Size] = for(i <- Arbitrary.arbitrary[Int] if i != Int.MinValue) yield Size(math.abs(i)) + implicit def aTagMap = Arbitrary(tagMap) implicit def aTagAndFrequency = Arbitrary(tagAndFrequency) implicit def aTag = Arbitrary(tag) + implicit def aSize = Arbitrary(size) property("exclusive allows all groups without the exclusive tag") = forAll { (tm: TagMap, tag: Tag) => excl(tag)(tm - tag) } - property("exclusive only allows a group with an excusive tag when the size is one") = forAll { (tm: TagMap, size: Int, etag: Tag) => - val tm2: TagMap = tm.updated(etag, math.abs(size)) - excl(etag)(tm2) == (size <= 1) + + property("exclusive only allows a group with an excusive tag when the size is one") = forAll { (tm: TagMap, size: Size, etag: Tag) => + val absSize = size.value + val tm2: TagMap = tm.updated(etag, absSize).updated(Tags.All, tm.getOrElse(Tags.All, 0) + absSize) + (s"TagMap: $tm2") |: + ( excl(etag)(tm2) == (absSize <= 1) ) } + property("exclusive always allows a group of size one") = forAll { (etag: Tag, mapTag: Tag) => - val tm: TagMap = Map(mapTag -> 1) + val tm: TagMap = Map(mapTag -> 1, Tags.All -> 1) excl(etag)(tm) }