From 5cc908478babb01523ca078bef8054e247f4b566 Mon Sep 17 00:00:00 2001 From: widmogrod Date: Wed, 20 Dec 2017 18:20:48 +0100 Subject: [PATCH] Functiona\filter test --- src/Functional/listt.php | 23 ---------------------- test/Functional/FilterTest.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 test/Functional/FilterTest.php diff --git a/src/Functional/listt.php b/src/Functional/listt.php index 89bfb94..f757a38 100644 --- a/src/Functional/listt.php +++ b/src/Functional/listt.php @@ -52,29 +52,6 @@ function concat(Foldable $xs) }, Listt::mempty(), $xs); } -///** -// * map f xs is the list obtained by applying f to each element of xs, i.e., -// * -// * map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] -// * map f [x1, x2, ...] == [f x1, f x2, ...] -// */ -//function map() -//{ -// // TODO -//} -// -///** -// * filter :: (a -> Bool) -> [a] -> [a] Source # -// * -// * filter, applied to a predicate and a list, returns the list of those elements that satisfy the predicate; i.e., -// * -// * filter p xs = [ x | x <- xs, p x] -// */ -//function filter() -//{ -// // TODO -//} - const prepend = 'Widmogrod\Functional\prepend'; /** diff --git a/test/Functional/FilterTest.php b/test/Functional/FilterTest.php new file mode 100644 index 0000000..7242c57 --- /dev/null +++ b/test/Functional/FilterTest.php @@ -0,0 +1,44 @@ +assertEquals( + $expected, + filter($filter, $list) + ); + } + + public function provideData() + { + return [ + 'simple list' => [ + '$list' => fromIterable([1, 2, 3, 4, 5]), + '$expected' => fromIterable([1, 3, 5]) + ], + 'empty list' => [ + '$list' => fromIterable([]), + '$expected' => fromIterable([]) + ], + 'traversable' => [ + '$list' => fromIterable(new \ArrayIterator([1, 2, 3, 4, 5])), + '$expected' => fromIterable([1, 3, 5]), + ], + ]; + } +} -- 2.11.0