From 77fbb3cbdb61f64a47bb4da5c05337b69e283212 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 28 Dec 2022 10:59:39 +0100 Subject: [PATCH] Add new acceptance test scenario: 034 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` Error: × Main thread panicked. ├─▶ at /Users/ktorz/Documents/Projects/aiken-lang/aiken/crates/aiken-project/src/lib.rs:670:22 ╰─▶ called `Result::unwrap()` on an `Err` value: FreeUnique(Name { text: "aiken/list_foldr_list_data_data_list_data", unique: Unique(1) }) ``` --- examples/acceptance_tests/034/aiken.lock | 5 +++++ examples/acceptance_tests/034/aiken.toml | 2 ++ examples/acceptance_tests/034/lib/tests.ak | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 examples/acceptance_tests/034/aiken.lock create mode 100644 examples/acceptance_tests/034/aiken.toml create mode 100644 examples/acceptance_tests/034/lib/tests.ak diff --git a/examples/acceptance_tests/034/aiken.lock b/examples/acceptance_tests/034/aiken.lock new file mode 100644 index 00000000..3a78b1e7 --- /dev/null +++ b/examples/acceptance_tests/034/aiken.lock @@ -0,0 +1,5 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +requirements = [] +packages = [] diff --git a/examples/acceptance_tests/034/aiken.toml b/examples/acceptance_tests/034/aiken.toml new file mode 100644 index 00000000..a81d1f44 --- /dev/null +++ b/examples/acceptance_tests/034/aiken.toml @@ -0,0 +1,2 @@ +name = "aiken-lang/acceptance_test_034" +version = "0.0.0" diff --git a/examples/acceptance_tests/034/lib/tests.ak b/examples/acceptance_tests/034/lib/tests.ak new file mode 100644 index 00000000..a215135f --- /dev/null +++ b/examples/acceptance_tests/034/lib/tests.ak @@ -0,0 +1,18 @@ +pub fn foldr(self: List, with: fn(a, b) -> b, zero: b) -> b { + when self is { + [] -> zero + [x, ..xs] -> with(x, foldr(xs, with, zero)) + } +} + +pub fn flat_map(self: List, with: fn(a) -> List) -> List { + foldr(self, fn(x, xs) { concat(with(x), xs) }, []) +} + +test flat_map_1() { + flat_map([], fn(a) { [a] }) == [] +} + +test flat_map_2() { + flat_map([1, 2, 3], fn(a) { [a, a] }) == [1, 1, 2, 2, 3, 3] +}