Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 27, 2023 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/fc2c6abb92f60baa5333207a64ef329a to your computer and use it in GitHub Desktop.
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/e4335b079820d7d31ba460530d30496dd43b7dbf
// summary : simple properties based scalacheck usage example
// keywords : scala, scalacheck, properties-based-testing, @testable
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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.3.0"
//> 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