Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:22
Show Gist options
  • Select an option

  • Save dacr/fc2c6abb92f60baa5333207a64ef329a to your computer and use it in GitHub Desktop.

Select an option

Save dacr/fc2c6abb92f60baa5333207a64ef329a to your computer and use it in GitHub Desktop.
simple properties based scalacheck usage example / published by https://github.com/dacr/code-examples-manager #221c6449-dad8-4d70-b690-1e689ecc01f5/426cf217c15730beeb67ada67713b48b5088b64e
// summary : simple properties based scalacheck usage example
// keywords : scala, scalacheck, properties-based-testing, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 221c6449-dad8-4d70-b690-1e689ecc01f5
// created-on : 2021-12-17T16:45:11+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "org.scalacheck::scalacheck:1.17.0"
// ---------------------
import org.scalacheck.Prop
import org.scalacheck.Gen
// -----------------------------
def concatList[A](left: List[A], right: List[A]): List[A] = left ::: right
val propConcatLists = Prop.forAll { (l1: List[Int], l2: List[Int]) =>
l1.size + l2.size == concatList(l1, l2).size
}
propConcatLists.check()
// -----------------------------
val propSqrt = Prop.forAll { (n: Int) => scala.math.sqrt(n*n) == n }
propSqrt.check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment