More test cases

This commit is contained in:
Dan Doel 2022-09-12 17:38:46 -04:00
parent a0966e2975
commit 1e4c62b3e3
11 changed files with 258 additions and 1 deletions

View File

@ -77,10 +77,12 @@ serialTests = do
New test results:
◉ serialTests case-02
◉ serialTests case-03
◉ serialTests case-00
◉ serialTests case-01
2 test(s) passing
4 test(s) passing
Tip: Use view serialTests to view the source of a test.

View File

@ -0,0 +1,39 @@
```ucm:hide
.> builtins.mergeio
```
```unison
structural ability Exit a where
exit : a -> b
prod : [Nat] -> Nat
prod l =
loop acc = cases
[] -> acc
0 +: _ -> exit 0
n +: ns -> loop (acc * n) ns
handle loop 0 l with cases
{ exit v -> _ } -> v
{ p } -> p
l1 = [1,3,5,7,9]
l2 = [1,2,0,3,4,5,6,7,8]
l3 = [1,2,4,8,16,3,5,6]
products = cases (x, y, z) ->
px = prod x
py = prod y
pz = prod z
"(" ++ toText px ++ ", " ++ toText py ++ ", \"" ++ toText pz ++ "\")"
mkTestCase = do
saveTestCase "case-02" products (l1, l2, l3)
```
```ucm
.> add
.> run mkTestCase
```

View File

@ -0,0 +1,66 @@
```unison
structural ability Exit a where
exit : a -> b
prod : [Nat] -> Nat
prod l =
loop acc = cases
[] -> acc
0 +: _ -> exit 0
n +: ns -> loop (acc * n) ns
handle loop 0 l with cases
{ exit v -> _ } -> v
{ p } -> p
l1 = [1,3,5,7,9]
l2 = [1,2,0,3,4,5,6,7,8]
l3 = [1,2,4,8,16,3,5,6]
products = cases (x, y, z) ->
px = prod x
py = prod y
pz = prod z
"(" ++ toText px ++ ", " ++ toText py ++ ", \"" ++ toText pz ++ "\")"
mkTestCase = do
saveTestCase "case-02" products (l1, l2, l3)
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
structural ability Exit a
l1 : [Nat]
l2 : [Nat]
l3 : [Nat]
mkTestCase : '{IO, Exception} ()
prod : [Nat] -> Nat
products : ([Nat], [Nat], [Nat]) -> Text
```
```ucm
.> add
⍟ I've added these definitions:
structural ability Exit a
l1 : [Nat]
l2 : [Nat]
l3 : [Nat]
mkTestCase : '{IO, Exception} ()
prod : [Nat] -> Nat
products : ([Nat], [Nat], [Nat]) -> Text
.> run mkTestCase
()
```

View File

@ -0,0 +1,53 @@
```ucm:hide
.> builtins.mergeio
```
```unison
structural ability DC r where
shift : ((a -> r) -> r) -> a
structural type Delayed r = Done r | Delay (Nat -> Delayed r)
hreset : Request {DC r} r -> r
hreset = cases
{ shift e -> k } ->
e (x -> handle k x with hreset)
{ x } -> x
reset : '{DC r} r -> r
reset body = handle !body with hreset
suspSum l =
walk acc = cases
[] -> acc
x +: xs
| x == 0 -> walk (shift (k -> Delay (x -> k (acc + x)))) xs
| otherwise -> walk (acc + x) xs
reset '(Done (walk 0 l))
l1 = [1, 2, 0, 3, 4, 0, 5, 6, 0, 7, 8]
l2 = [2, 0, 3, 0, 1, 0, 5, 0, 4, 0, 6]
l3 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
feed m = cases
Done r -> r
Delay f -> feed m (f m)
finish : (Delayed Nat, Delayed Nat, Delayed Nat) -> Text
finish = cases (x, y, z) ->
px = feed 2 x
py = feed 2 y
pz = feed 2 z
"(" ++ toText px ++ ", " ++ toText py ++ ", \"" ++ toText pz ++ "\")"
mkTestCase = do
trip = (suspSum l1, suspSum l2, suspSum l3)
saveTestCase "case-03" finish trip
```
```ucm
.> add
.> run mkTestCase
```

View File

@ -0,0 +1,89 @@
```unison
structural ability DC r where
shift : ((a -> r) -> r) -> a
structural type Delayed r = Done r | Delay (Nat -> Delayed r)
hreset : Request {DC r} r -> r
hreset = cases
{ shift e -> k } ->
e (x -> handle k x with hreset)
{ x } -> x
reset : '{DC r} r -> r
reset body = handle !body with hreset
suspSum l =
walk acc = cases
[] -> acc
x +: xs
| x == 0 -> walk (shift (k -> Delay (x -> k (acc + x)))) xs
| otherwise -> walk (acc + x) xs
reset '(Done (walk 0 l))
l1 = [1, 2, 0, 3, 4, 0, 5, 6, 0, 7, 8]
l2 = [2, 0, 3, 0, 1, 0, 5, 0, 4, 0, 6]
l3 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
feed m = cases
Done r -> r
Delay f -> feed m (f m)
finish : (Delayed Nat, Delayed Nat, Delayed Nat) -> Text
finish = cases (x, y, z) ->
px = feed 2 x
py = feed 2 y
pz = feed 2 z
"(" ++ toText px ++ ", " ++ toText py ++ ", \"" ++ toText pz ++ "\")"
mkTestCase = do
trip = (suspSum l1, suspSum l2, suspSum l3)
saveTestCase "case-03" finish trip
```
```ucm
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
structural ability DC r
structural type Delayed r
feed : Nat -> Delayed r -> r
finish : (Delayed Nat, Delayed Nat, Delayed Nat)
-> Text
hreset : Request {DC r} r -> r
l1 : [Nat]
l2 : [Nat]
l3 : [Nat]
mkTestCase : '{IO, Exception} ()
reset : '{DC r} r -> r
suspSum : [Nat] -> Delayed Nat
```
```ucm
.> add
⍟ I've added these definitions:
structural ability DC r
structural type Delayed r
feed : Nat -> Delayed r -> r
finish : (Delayed Nat, Delayed Nat, Delayed Nat) -> Text
hreset : Request {DC r} r -> r
l1 : [Nat]
l2 : [Nat]
l3 : [Nat]
mkTestCase : '{IO, Exception} ()
reset : '{DC r} r -> r
suspSum : [Nat] -> Delayed Nat
.> run mkTestCase
()
```

View File

@ -0,0 +1,3 @@
8 ´ýÕ§=£ÒÄwñÛ¶”¢à•ßJ
ˆp
¾4ÙXÍØgâ†r…+I…»h´UÉR”3DõÓT

View File

@ -0,0 +1 @@
(0, 0, "0")

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
ÅwÑKœ6«Þ<19>fŸÔݼ;ð}¼ê·˜@Άo<E280A0>(¯Û¦ÿ.HÖü±¼T€9Wj35o2O|mfÈ-

View File

@ -0,0 +1 @@
(42, 31, "45")

File diff suppressed because one or more lines are too long