Last active
May 25, 2024 10:19
-
-
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/f040e1aa575ea747cfcb4dbbeb680a15f8adfe4b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.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