chore: converted acceptance tests 5-7
This commit is contained in:
@@ -48,3 +48,4 @@ uplc = { path = '../uplc', version = "1.0.2-alpha" }
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "1.1.0"
|
||||
pretty_assertions = "1.3.0"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use aiken_lang::ast::{Definition, Function};
|
||||
use uplc::{
|
||||
ast::{Constant, DeBruijn, Name, Program, Term},
|
||||
ast::{Constant, DeBruijn, Name, Program, Term, Type},
|
||||
machine::cost_model::ExBudget,
|
||||
optimize, BigInt, Constr, PlutusData,
|
||||
};
|
||||
@@ -62,44 +64,22 @@ fn assert_uplc(source_code: &str, expected: Term<Name>) {
|
||||
assert!(!eval.failed())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_6_if_else() {
|
||||
let src = r#"
|
||||
test bar() {
|
||||
let x = 1
|
||||
if x == 1 {
|
||||
True
|
||||
} else {
|
||||
False
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_integer()
|
||||
.apply(Term::integer(1.into()))
|
||||
.apply(Term::integer(1.into()))
|
||||
.delayed_if_else(Term::bool(true), Term::bool(false)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_1_length() {
|
||||
let src = r#"
|
||||
pub fn length(xs: List<a>) -> Int {
|
||||
when xs is {
|
||||
[] ->
|
||||
0
|
||||
[_, ..rest] ->
|
||||
1 + length(rest)
|
||||
}
|
||||
}
|
||||
pub fn length(xs: List<a>) -> Int {
|
||||
when xs is {
|
||||
[] ->
|
||||
0
|
||||
[_, ..rest] ->
|
||||
1 + length(rest)
|
||||
}
|
||||
}
|
||||
|
||||
test length_1() {
|
||||
length([1, 2, 3]) == 3
|
||||
}
|
||||
"#;
|
||||
test length_1() {
|
||||
length([1, 2, 3]) == 3
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
@@ -139,18 +119,18 @@ fn acceptance_test_1_length() {
|
||||
#[test]
|
||||
fn acceptance_test_2_repeat() {
|
||||
let src = r#"
|
||||
pub fn repeat(x: a, n: Int) -> List<a> {
|
||||
if n <= 0 {
|
||||
[]
|
||||
} else {
|
||||
[x, ..repeat(x, n - 1)]
|
||||
}
|
||||
}
|
||||
pub fn repeat(x: a, n: Int) -> List<a> {
|
||||
if n <= 0 {
|
||||
[]
|
||||
} else {
|
||||
[x, ..repeat(x, n - 1)]
|
||||
}
|
||||
}
|
||||
|
||||
test repeat_1() {
|
||||
repeat("aiken", 2) == ["aiken", "aiken"]
|
||||
}
|
||||
"#;
|
||||
test repeat_1() {
|
||||
repeat("aiken", 2) == ["aiken", "aiken"]
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
@@ -198,23 +178,23 @@ fn acceptance_test_2_repeat() {
|
||||
#[test]
|
||||
fn acceptance_test_3_concat() {
|
||||
let src = r#"
|
||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] ->
|
||||
zero
|
||||
[x, ..rest] ->
|
||||
f(x, foldr(rest, f, zero))
|
||||
}
|
||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] ->
|
||||
zero
|
||||
[x, ..rest] ->
|
||||
f(x, foldr(rest, f, zero))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn concat(left: List<a>, right: List<a>) -> List<a> {
|
||||
foldr(left, fn(x, xs) { [x, ..xs] }, right)
|
||||
}
|
||||
pub fn concat(left: List<a>, right: List<a>) -> List<a> {
|
||||
foldr(left, fn(x, xs) { [x, ..xs] }, right)
|
||||
}
|
||||
|
||||
test concat_1() {
|
||||
concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
"#;
|
||||
test concat_1() {
|
||||
concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
@@ -292,27 +272,27 @@ fn acceptance_test_3_concat() {
|
||||
#[test]
|
||||
fn acceptance_test_4_concat_no_anon_func() {
|
||||
let src = r#"
|
||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] ->
|
||||
zero
|
||||
[x, ..rest] ->
|
||||
f(x, foldr(rest, f, zero))
|
||||
}
|
||||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] ->
|
||||
zero
|
||||
[x, ..rest] ->
|
||||
f(x, foldr(rest, f, zero))
|
||||
}
|
||||
|
||||
pub fn prepend(x: a, xs: List<a>) -> List<a> {
|
||||
[x, ..xs]
|
||||
}
|
||||
|
||||
pub fn concat(left: List<a>, right: List<a>) -> List<a> {
|
||||
foldr(left, prepend, right)
|
||||
}
|
||||
|
||||
test concat_1() {
|
||||
concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
"#;
|
||||
}
|
||||
|
||||
pub fn prepend(x: a, xs: List<a>) -> List<a> {
|
||||
[x, ..xs]
|
||||
}
|
||||
|
||||
pub fn concat(left: List<a>, right: List<a>) -> List<a> {
|
||||
foldr(left, prepend, right)
|
||||
}
|
||||
|
||||
test concat_1() {
|
||||
concat([1, 2, 3], [4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
@@ -392,19 +372,19 @@ fn acceptance_test_4_concat_no_anon_func() {
|
||||
#[test]
|
||||
fn acceptance_test_5_head_not_empty() {
|
||||
let src = r#"
|
||||
use aiken/builtin.{head_list}
|
||||
use aiken/builtin.{head_list}
|
||||
|
||||
pub fn head(xs: List<a>) -> Option<a> {
|
||||
when xs is {
|
||||
[] -> None
|
||||
_ -> Some(head_list(xs))
|
||||
}
|
||||
pub fn head(xs: List<a>) -> Option<a> {
|
||||
when xs is {
|
||||
[] -> None
|
||||
_ -> Some(head_list(xs))
|
||||
}
|
||||
|
||||
test head_1() {
|
||||
head([1, 2, 3]) == Some(1)
|
||||
}
|
||||
"#;
|
||||
}
|
||||
|
||||
test head_1() {
|
||||
head([1, 2, 3]) == Some(1)
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
@@ -447,3 +427,272 @@ fn acceptance_test_5_head_not_empty() {
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_5_head_empty() {
|
||||
let src = r#"
|
||||
use aiken/builtin.{head_list}
|
||||
|
||||
pub fn head(xs: List<a>) -> Option<a> {
|
||||
when xs is {
|
||||
[] -> None
|
||||
_ -> Some(head_list(xs))
|
||||
}
|
||||
}
|
||||
|
||||
test head_1() {
|
||||
head([]) == None
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_data()
|
||||
.apply(
|
||||
Term::var("head")
|
||||
.lambda("head")
|
||||
.apply(
|
||||
Term::var("xs")
|
||||
.delayed_choose_list(
|
||||
Term::Constant(
|
||||
Constant::Data(PlutusData::Constr(Constr {
|
||||
tag: 122,
|
||||
any_constructor: None,
|
||||
fields: vec![],
|
||||
}))
|
||||
.into(),
|
||||
),
|
||||
Term::constr_data().apply(Term::integer(0.into())).apply(
|
||||
Term::mk_cons()
|
||||
.apply(Term::head_list().apply(Term::var("xs")))
|
||||
.apply(Term::empty_list()),
|
||||
),
|
||||
)
|
||||
.lambda("xs"),
|
||||
)
|
||||
.apply(Term::list_values(vec![])),
|
||||
)
|
||||
.apply(Term::Constant(
|
||||
Constant::Data(PlutusData::Constr(Constr {
|
||||
tag: 122,
|
||||
any_constructor: None,
|
||||
fields: vec![],
|
||||
}))
|
||||
.into(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_6_if_else() {
|
||||
let src = r#"
|
||||
test bar() {
|
||||
let x = 1
|
||||
if x == 1 {
|
||||
True
|
||||
} else {
|
||||
False
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_integer()
|
||||
.apply(Term::integer(1.into()))
|
||||
.apply(Term::integer(1.into()))
|
||||
.delayed_if_else(Term::bool(true), Term::bool(false)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_6_equals() {
|
||||
let src = r#"
|
||||
test foo() {
|
||||
(1, []) == (1, [])
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_data()
|
||||
.apply(
|
||||
Term::map_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(Term::Constant(
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::BigInt(BigInt::Int(1.into()))).into(),
|
||||
Constant::Data(PlutusData::Array(vec![])).into(),
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
.apply(Term::empty_map()),
|
||||
),
|
||||
)
|
||||
.apply(
|
||||
Term::map_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(Term::Constant(
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::BigInt(BigInt::Int(1.into()))).into(),
|
||||
Constant::Data(PlutusData::Array(vec![])).into(),
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
.apply(Term::empty_map()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn acceptance_test_7_unzip() {
|
||||
let src = r#"
|
||||
pub fn unzip(xs: List<(a, b)>) -> (List<a>, List<b>) {
|
||||
when xs is {
|
||||
[] -> ([], [])
|
||||
[(a, b), ..rest] -> {
|
||||
let (a_tail, b_tail) = unzip(rest)
|
||||
([a, ..a_tail], [b, ..b_tail])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test unzip1() {
|
||||
let x = [(3, #"55"), (4, #"7799")]
|
||||
|
||||
unzip(x) == ([3, 4], [#"55", #"7799"])
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_data()
|
||||
.apply(
|
||||
Term::map_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(
|
||||
Term::var("unzip")
|
||||
.lambda("unzip")
|
||||
.apply(Term::var("unzip").apply(Term::var("unzip")))
|
||||
.lambda("unzip")
|
||||
.apply(
|
||||
Term::var("xs")
|
||||
.delayed_choose_list(
|
||||
Term::Constant(
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::Array(vec![]))
|
||||
.into(),
|
||||
Constant::Data(PlutusData::Array(vec![]))
|
||||
.into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
Term::mk_pair_data()
|
||||
.apply(
|
||||
Term::list_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(
|
||||
Term::i_data()
|
||||
.apply(Term::var("a")),
|
||||
)
|
||||
.apply(Term::var("a_tail")),
|
||||
),
|
||||
)
|
||||
.apply(
|
||||
Term::list_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(
|
||||
Term::b_data()
|
||||
.apply(Term::var("b")),
|
||||
)
|
||||
.apply(Term::var("b_tail")),
|
||||
),
|
||||
)
|
||||
.lambda("b_tail")
|
||||
.apply(Term::unlist_data().apply(
|
||||
Term::snd_pair().apply(Term::var("tail_pair")),
|
||||
))
|
||||
.lambda("a_tail")
|
||||
.apply(Term::unlist_data().apply(
|
||||
Term::fst_pair().apply(Term::var("tail_pair")),
|
||||
))
|
||||
.lambda("tail_pair")
|
||||
.apply(
|
||||
Term::var("unzip")
|
||||
.apply(Term::var("unzip"))
|
||||
.apply(Term::var("rest")),
|
||||
)
|
||||
.lambda("a")
|
||||
.apply(Term::un_i_data().apply(
|
||||
Term::fst_pair().apply(Term::var("head_pair")),
|
||||
))
|
||||
.lambda("b")
|
||||
.apply(Term::un_b_data().apply(
|
||||
Term::snd_pair().apply(Term::var("head_pair")),
|
||||
))
|
||||
.lambda("rest")
|
||||
.apply(Term::tail_list().apply(Term::var("xs")))
|
||||
.lambda("head_pair")
|
||||
.apply(Term::head_list().apply(Term::var("xs"))),
|
||||
)
|
||||
.lambda("xs")
|
||||
.lambda("unzip"),
|
||||
)
|
||||
.apply(Term::var("x")),
|
||||
)
|
||||
.apply(Term::empty_map()),
|
||||
),
|
||||
)
|
||||
.apply(
|
||||
Term::map_data().apply(
|
||||
Term::mk_cons()
|
||||
.apply(Term::Constant(
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::Array(vec![
|
||||
PlutusData::BigInt(BigInt::Int(3.into())),
|
||||
PlutusData::BigInt(BigInt::Int(4.into())),
|
||||
]))
|
||||
.into(),
|
||||
Constant::Data(PlutusData::Array(vec![
|
||||
PlutusData::BoundedBytes(vec![85].into()),
|
||||
PlutusData::BoundedBytes(vec![119, 153].into()),
|
||||
]))
|
||||
.into(),
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
.apply(Term::empty_map()),
|
||||
),
|
||||
)
|
||||
.lambda("x")
|
||||
.apply(Term::Constant(
|
||||
Constant::ProtoList(
|
||||
Type::Pair(Type::Data.into(), Type::Data.into()),
|
||||
vec![
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::BigInt(BigInt::Int(3.into()))).into(),
|
||||
Constant::Data(PlutusData::BoundedBytes(vec![85].into())).into(),
|
||||
),
|
||||
Constant::ProtoPair(
|
||||
Type::Data,
|
||||
Type::Data,
|
||||
Constant::Data(PlutusData::BigInt(BigInt::Int(4.into()))).into(),
|
||||
Constant::Data(PlutusData::BoundedBytes(vec![119, 153].into())).into(),
|
||||
),
|
||||
],
|
||||
)
|
||||
.into(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user