-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example runs but doesn't demonstrate what I want #bruce #time 45m
- Loading branch information
Bruce Eckel
committed
Jul 20, 2024
1 parent
da49fe7
commit de4ad35
Showing
2 changed files
with
54 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package experiments | ||
|
||
import zio.* | ||
import zio.test.* | ||
|
||
case object ErrorObject1: | ||
val msg = "Failed: ErrorObject1" | ||
case object ErrorObject2 extends Exception("Failed: ErrorObject2") | ||
|
||
def matchTo1(n: Int) = | ||
if n == 1 then | ||
ZIO.fail("Failed at 1") | ||
else | ||
ZIO.succeed("Passed 1") | ||
|
||
def matchTo2(n: Int) = | ||
if n == 2 then | ||
ZIO.fail(ErrorObject1) | ||
else | ||
ZIO.succeed("Passed 2") | ||
|
||
def matchTo3(n: Int) = | ||
if n == 3 then | ||
ZIO.fail(ErrorObject2) | ||
else | ||
ZIO.succeed("Passed 3") | ||
|
||
def completeTo(n: Int) = | ||
defer: | ||
val r1 = matchTo1(n).run | ||
val r2 = matchTo2(n).run | ||
val r3 = matchTo3(n).run | ||
printLine(s"Success: $r1 $r2 $r3").run | ||
|
||
object FailVarieties extends ZIOSpecDefault: | ||
def spec = | ||
suite("Suite of Tests")( | ||
test("one"): | ||
completeTo(1) | ||
assertCompletes | ||
, | ||
test("two"): | ||
completeTo(2) | ||
assertCompletes | ||
, | ||
test("three"): | ||
completeTo(3) | ||
assertCompletes | ||
, | ||
test("four"): | ||
completeTo(4) | ||
assertCompletes | ||
, | ||
) |