Functional\iterate tests
authorwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 17:58:19 +0000 (18:58 +0100)
committerwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 17:58:19 +0000 (18:58 +0100)
test/Functional/IterateTest.php [new file with mode: 0644]

diff --git a/test/Functional/IterateTest.php b/test/Functional/IterateTest.php
new file mode 100644 (file)
index 0000000..464e0e5
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+namespace test\Functional;
+
+use Eris\Generator;
+use Eris\TestTrait;
+use function Widmogrod\Functional\eql;
+use function Widmogrod\Functional\filter;
+use function Widmogrod\Functional\foldr;
+use const Widmogrod\Functional\identity;
+use function Widmogrod\Functional\iterate;
+use function Widmogrod\Functional\length;
+use function Widmogrod\Functional\take;
+
+class IterateTest extends \PHPUnit_Framework_TestCase
+{
+    use TestTrait;
+
+    public function test_it_should_generate_infinite_list()
+    {
+        $this->forAll(
+            Generator\choose(1, 100),
+            Generator\int()
+        )->then(function ($n, $value) {
+            $list = take($n, iterate(identity, $value));
+
+            return length($list) === $n;
+        });
+    }
+
+    public function test_it_should_generate_repetive_value()
+    {
+        $this->forAll(
+            Generator\choose(1, 100),
+            Generator\int()
+        )->then(function ($n, $value) {
+            $list = take($n, iterate(function ($i) {
+                return $i + 1;
+            }, $value));
+
+            return length(filter(eql($value), $list)) === $n
+                && $value + $n === foldr(identity, $list);
+        });
+    }
+}