Last active
May 25, 2024 10:19
-
-
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/c0857b3df40cf548fae0e4ae9cb6a3c4a6dfeed6
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 : 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.4.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