Basic scalacheck properties for ByteString
This commit is contained in:
parent
23dcb5d1fe
commit
dabf14ef4b
1 changed files with 38 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package akka.util
|
||||
|
||||
import org.scalatest.WordSpec
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.prop.Checkers
|
||||
import org.scalacheck._
|
||||
import org.scalacheck.Arbitrary._
|
||||
import org.scalacheck.Prop._
|
||||
import org.scalacheck.Gen._
|
||||
|
||||
class ByteStringSpec extends WordSpec with MustMatchers with Checkers {
|
||||
|
||||
def genSimpleByteString(min: Int, max: Int) = for {
|
||||
n ← choose(min, max)
|
||||
b ← Gen.containerOfN[Array, Byte](n, arbitrary[Byte])
|
||||
} yield ByteString(b)
|
||||
|
||||
implicit val arbitraryByteString: Arbitrary[ByteString] = Arbitrary {
|
||||
Gen.sized { s ⇒
|
||||
for {
|
||||
chunks ← choose(0, s)
|
||||
bytes ← listOfN(chunks, genSimpleByteString(1, s / (chunks max 1)))
|
||||
} yield (ByteString.empty /: bytes)(_ ++ _)
|
||||
}
|
||||
}
|
||||
|
||||
"A ByteString" must {
|
||||
"have correct size" when {
|
||||
"concatenating" in { check((a: ByteString, b: ByteString) ⇒ (a ++ b).size == a.size + b.size) }
|
||||
"dropping" in { check((a: ByteString, b: ByteString) ⇒ (a ++ b).drop(b.size).size == a.size) }
|
||||
}
|
||||
"be sequential" when {
|
||||
"taking" in { check((a: ByteString, b: ByteString) ⇒ (a ++ b).take(a.size) == a) }
|
||||
"dropping" in { check((a: ByteString, b: ByteString) ⇒ (a ++ b).drop(a.size) == b) }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue