Skip to content

Commit

Permalink
Add budget tests for asData (#5608)
Browse files Browse the repository at this point in the history
  • Loading branch information
zliu41 authored Nov 8, 2023
1 parent 930e18d commit c5c1c39
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plutus-tx-plugin/plutus-tx-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ test-suite plutus-tx-tests
hs-source-dirs: test
main-is: Spec.hs
other-modules:
AsData.Budget.Spec
AsData.Budget.Types
Budget.Spec
IntegerLiterals.NoStrict.NegativeLiterals.Spec
IntegerLiterals.NoStrict.NoNegativeLiterals.Spec
Expand Down Expand Up @@ -160,6 +162,7 @@ test-suite plutus-tx-tests
, base >=4.9 && <5
, containers
, deepseq
, filepath
, flat ^>=0.6
, hedgehog
, lens
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 2729622
| mem: 8250})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
let
data Bool | Bool_match where
True : Bool
False : Bool
in
\(d : data) ->
let
!tup : pair integer (list data) = unConstrData d
in
ifThenElse
{all dead. integer}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
!ds : integer = unIData (headList {data} l)
!ds : integer = unIData (headList {data} l)
!ds : integer = unIData (headList {data} (tailList {data} l))
in
unIData (headList {data} l))
(/\dead -> error {integer})
{all dead. dead}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 4752053
| mem: 14356})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 100)
77 changes: 77 additions & 0 deletions plutus-tx-plugin/test/AsData/Budget/9.2/patternMatching.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
let
data (Tuple4 :: * -> * -> * -> * -> *) a b c d | Tuple4_match where
Tuple4 : a -> b -> c -> d -> Tuple4 a b c d
data Bool | Bool_match where
True : Bool
False : Bool
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
in
\(d : data) ->
let
!ds : Tuple4 integer integer integer integer
= (let
r = Tuple4 integer integer integer integer
in
\(scrut : data)
(cont : integer -> integer -> integer -> integer -> r)
(fail : unit -> r) ->
let
!tup : pair integer (list data) = unConstrData scrut
in
ifThenElse
{all dead. r}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
in
cont
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} (tailList {data} l))))
(/\dead -> fail ())
{all dead. dead})
d
(\(x : integer) (y : integer) (z : integer) (w : integer) ->
Tuple4 {integer} {integer} {integer} {integer} x y z w)
(\(void : unit) -> error {Tuple4 integer integer integer integer})
in
addInteger
(addInteger
(addInteger
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> x))
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> y)))
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> z)))
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> w))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 12986619
| mem: 39006})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 100)
64 changes: 64 additions & 0 deletions plutus-tx-plugin/test/AsData/Budget/9.2/recordFields.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
!`$mInts` :
all r.
data ->
(integer -> integer -> integer -> integer -> r) ->
(unit -> r) ->
r
= /\r ->
\(scrut : data)
(cont : integer -> integer -> integer -> integer -> r)
(fail : unit -> r) ->
let
!tup : pair integer (list data) = unConstrData scrut
in
ifThenElse
{all dead. r}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
in
cont
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} (tailList {data} l))))
(/\dead -> fail ())
{all dead. dead}
data Bool | Bool_match where
True : Bool
False : Bool
in
\(d : data) ->
let
!x : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!y : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!z : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!w : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
in
addInteger (addInteger (addInteger x y) z) w
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 2729622
| mem: 8250})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
let
data Bool | Bool_match where
True : Bool
False : Bool
in
\(d : data) ->
let
!tup : pair integer (list data) = unConstrData d
in
ifThenElse
{all dead. integer}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
!ds : integer = unIData (headList {data} l)
!ds : integer = unIData (headList {data} l)
!ds : integer = unIData (headList {data} (tailList {data} l))
in
unIData (headList {data} l))
(/\dead -> error {integer})
{all dead. dead}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 3786053
| mem: 10156})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 100)
53 changes: 53 additions & 0 deletions plutus-tx-plugin/test/AsData/Budget/9.6/patternMatching.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
let
data Unit | Unit_match where
Unit : Unit
data (Tuple4 :: * -> * -> * -> * -> *) a b c d | Tuple4_match where
Tuple4 : a -> b -> c -> d -> Tuple4 a b c d
data Bool | Bool_match where
True : Bool
False : Bool
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
in
\(d : data) ->
Tuple4_match
{integer}
{integer}
{integer}
{integer}
((let
r = Tuple4 integer integer integer integer
in
\(scrut : data)
(cont : integer -> integer -> integer -> integer -> r)
(fail : unit -> r) ->
let
!tup : pair integer (list data) = unConstrData scrut
in
ifThenElse
{all dead. r}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
in
cont
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} (tailList {data} l))))
(/\dead -> fail ())
{all dead. dead})
d
(\(x : integer) (y : integer) (z : integer) (w : integer) ->
Tuple4 {integer} {integer} {integer} {integer} x y z w)
(\(void : unit) ->
Unit_match
(error {Unit})
{Tuple4 integer integer integer integer}
(error {Tuple4 integer integer integer integer})))
{integer}
(\(ipv : integer) (ipv : integer) (ipv : integer) (ipv : integer) ->
addInteger (addInteger (addInteger ipv ipv) ipv) ipv)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 12986619
| mem: 39006})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 100)
64 changes: 64 additions & 0 deletions plutus-tx-plugin/test/AsData/Budget/9.6/recordFields.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
!`$mInts` :
all r.
data ->
(integer -> integer -> integer -> integer -> r) ->
(unit -> r) ->
r
= /\r ->
\(scrut : data)
(cont : integer -> integer -> integer -> integer -> r)
(fail : unit -> r) ->
let
!tup : pair integer (list data) = unConstrData scrut
in
ifThenElse
{all dead. r}
(equalsInteger 0 (fstPair {integer} {list data} tup))
(/\dead ->
let
!l : list data = sndPair {integer} {list data} tup
!l : list data = tailList {data} l
!l : list data = tailList {data} l
in
cont
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} l))
(unIData (headList {data} (tailList {data} l))))
(/\dead -> fail ())
{all dead. dead}
data Bool | Bool_match where
True : Bool
False : Bool
in
\(d : data) ->
let
!x : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!y : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!z : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
!w : integer
= `$mInts`
{integer}
d
(\(ds : integer) (ds : integer) (ds : integer) (ds : integer) -> ds)
(\(void : unit) -> error {integer})
in
addInteger (addInteger (addInteger x y) z) w
Loading

0 comments on commit c5c1c39

Please sign in to comment.