Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active May 6, 2023 15:40
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/378e8e7eac15ed2b7e3c21fcb45a349c to your computer and use it in GitHub Desktop.
Save dacr/378e8e7eac15ed2b7e3c21fcb45a349c to your computer and use it in GitHub Desktop.
ZIO learning - zio properties based tests cheat sheet as tests / published by https://github.com/dacr/code-examples-manager #c3d6f389-abb1-4c21-bf62-ffaafc53ecea/8a0115eb11871cabe0cb62e902bd9ae887cfcbbd
// summary : ZIO learning - zio properties based tests cheat sheet as tests
// keywords : scala, scalacli, zio, ziotest, @testable, cheatsheet
// 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 : c3d6f389-abb1-4c21-bf62-ffaafc53ecea
// created-on : 2021-12-19T20:56:06+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.2.2"
//> using dep "dev.zio::zio:2.0.13"
//> using dep "dev.zio::zio-test:2.0.13"
// ---------------------
import zio.*
import zio.test.*
import zio.test.Assertion._
import java.io.{FileInputStream, FileNotFoundException, File}
import java.util.UUID
object PropertyBasedTests extends ZIOSpecDefault {
def spec = suite("learning zio property based tests")(
test("additions associativity")(
check(Gen.int, Gen.int, Gen.int)((x, y, z) => assertTrue((x + y) + z == x + (y + z)))
),
test("string length")(
check(Gen.stringBounded(1, 512)(Gen.char), Gen.string)((s1, s2) => assertTrue((s1 + s2).size == s1.size + s2.size))
)
)
}
PropertyBasedTests.main(Array.empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment