Update tests to phpunit=6
authorwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 19:38:35 +0000 (20:38 +0100)
committerwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 19:38:35 +0000 (20:38 +0100)
phpunit.xml.dist
src/Functional/infinit.php
src/Functional/miscellaneous.php
test/Functional/ConsttTest.php
test/Functional/CycleTest.php
test/Functional/IterateTest.php
test/Functional/RepeatTest.php
test/Functional/ReplicateTest.php
test/Functional/UnzipTest.php
test/Functional/ZipTest.php
test/Useful/MatchTest.php

index 5e2eec3..3d7323d 100644 (file)
@@ -1,25 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<phpunit
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
-        backupGlobals="true"
-        backupStaticAttributes="false"
-        cacheTokens="false"
-        colors="false"
-        convertErrorsToExceptions="true"
-        convertNoticesToExceptions="true"
-        convertWarningsToExceptions="true"
-        forceCoversAnnotation="false"
-        mapTestClassNameToCoveredClassName="false"
-        processIsolation="false"
-        stopOnError="false"
-        stopOnFailure="false"
-        stopOnIncomplete="false"
-        stopOnSkipped="false"
-        timeoutForSmallTests="1"
-        timeoutForMediumTests="10"
-        timeoutForLargeTests="60"
-        verbose="false">
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd">
     <testsuites>
         <testsuite name="Functional">
             <directory>./test/Functional</directory>
@@ -30,6 +11,9 @@
         <testsuite name="Primitive">
             <directory>./test/Primitive</directory>
         </testsuite>
+        <testsuite name="Useful">
+            <directory>./test/Useful</directory>
+        </testsuite>
         <testsuite name="Examples">
             <directory>./example/</directory>
         </testsuite>
index bbdcf58..7df1157 100644 (file)
@@ -6,7 +6,6 @@ use Widmogrod\Primitive\EmptyListError;
 use Widmogrod\Primitive\Listt;
 use Widmogrod\Primitive\ListtCons;
 use Widmogrod\Primitive\ListtNil;
-use function Widmogrod\Useful\match;
 
 /**
  * @var callable
@@ -86,26 +85,25 @@ const cycle = 'Widmogrod\Functional\cycle';
  *
  * cycle ties a finite list into a circular one, or equivalently, the infinite repetition of the original list. It is the identity on infinite lists.
  *
- * @param Listt $l
+ * @param Listt $xs
  * @return Listt
  * @throws EmptyListError
  */
-function cycle(Listt $l): Listt
+function cycle(Listt $xs): Listt
 {
-    if ($l instanceof ListtNil) {
+    if ($xs instanceof ListtNil) {
         throw new EmptyListError(__FUNCTION__);
     }
 
-    $cycle = match([
-        ListtNil::class => function () use (&$next) {
-            return $next;
-        },
-        ListtCons::class => identity
-    ]);
+    $cycle = function (Listt $xs, Listt $cycled) use (&$cycle) : Listt {
+        if ($cycled instanceof ListtNil) {
+            return cycle($xs);
+        }
 
-    $next = ListtCons::of(function () use ($l, $cycle) {
-        return [head($l), $cycle(tail($l))];
-    });
+        return ListtCons::of(function () use ($xs, $cycled, $cycle) {
+            return [head($cycled), $cycle($xs, tail($cycled))];
+        });
+    };
 
-    return $next;
+    return $cycle($xs, $xs);
 }
index 9379d9f..372dad4 100644 (file)
@@ -45,7 +45,7 @@ function constt($a, $b = null)
 {
     return curryN(2, function ($a) {
         return $a;
-    });
+    })(...func_get_args());
 }
 
 
index 78ebd1f..65ccbaf 100644 (file)
@@ -16,8 +16,8 @@ class ConsttTest extends \PHPUnit\Framework\TestCase
             Generator\int(),
             Generator\int()
         )->then(function ($a, $b) {
-            return constt($a, $b) === $a
-                && constt($a)($b) === $a;
+            $this->assertEquals($a, constt($a, $b));
+            $this->assertEquals($a, constt($a)($b));
         });
     }
 }
index 7034bec..410d1a1 100644 (file)
@@ -4,11 +4,9 @@ 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\cycle;
+use function Widmogrod\Functional\fromIterable;
 use function Widmogrod\Functional\iterate;
 use function Widmogrod\Functional\length;
 use function Widmogrod\Functional\take;
@@ -20,31 +18,24 @@ class CycleTest extends \PHPUnit\Framework\TestCase
     public function test_it_should_generate_infinite_list()
     {
         $this->forAll(
-            Generator\choose(1, 100),
+            Generator\choose(2, 100),
             Generator\int()
         )->then(function ($n, $value) {
             $list = cycle(take($n, iterate(identity, $value)));
             $list = take($n * 2, $list);
 
-            return length($list) === $n * 2;
+            $this->assertEquals($n * 2, length($list));
         });
     }
 
-    public function test_it_should_generate_repetive_value()
+    public function test_it_should_generate_repetitive_value()
     {
-        $this->forAll(
-            Generator\choose(1, 100),
-            Generator\int()
-        )->then(function ($n, $value) {
-            $addOne = function (int $i): int {
-                return $i + 1;
-            };
+        $list = cycle(fromIterable(['a', 1]));
+        $list = take(4, $list);
 
-            $list = cycle(take($n, iterate($addOne, $value)));
-            $list = take($n * 2, $list);
-
-            return length(filter(eql($value), $list)) === $n
-                &&  ($value + $n) * 2 === foldr(identity, $list);
-        });
+        $this->assertEquals(
+            ['a', 1, 'a', 1],
+            $list->extract()
+        );
     }
 }
index 731efec..f906ddb 100644 (file)
@@ -4,12 +4,10 @@ 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\reduce;
 use function Widmogrod\Functional\take;
 
 class IterateTest extends \PHPUnit\Framework\TestCase
@@ -19,19 +17,19 @@ class IterateTest extends \PHPUnit\Framework\TestCase
     public function test_it_should_generate_infinite_list()
     {
         $this->forAll(
-            Generator\choose(1, 100),
+            Generator\choose(5, 100),
             Generator\int()
         )->then(function ($n, $value) {
             $list = take($n, iterate(identity, $value));
 
-            return length($list) === $n;
+            $this->assertEquals($n, length($list));
         });
     }
 
     public function test_it_should_generate_repetive_value()
     {
         $this->forAll(
-            Generator\choose(1, 100),
+            Generator\choose(5, 100),
             Generator\int()
         )->then(function ($n, $value) {
             $addOne = function (int $i): int {
@@ -40,8 +38,12 @@ class IterateTest extends \PHPUnit\Framework\TestCase
 
             $list = take($n, iterate($addOne, $value));
 
-            return length(filter(eql($value), $list)) === $n
-                && $value + $n === foldr(identity, $list);
+            $this->assertEquals(
+                $value + $n - 1,
+                reduce(function ($agg, $i) {
+                    return $i;
+                }, 0, $list)
+            );
         });
     }
 }
index 269d89e..e2f8d2e 100644 (file)
@@ -22,7 +22,7 @@ class RepeatTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $value) {
             $list = take($n, repeat($value));
 
-            return length($list) === $n;
+            $this->assertEquals($n, length($list));
         });
     }
 
@@ -34,7 +34,7 @@ class RepeatTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $value) {
             $list = take($n, repeat($value));
 
-            return length(filter(eql($value), $list)) === $n;
+            return $this->assertEquals($n, length(filter(eql($value), $list)));
         });
     }
 }
index 5dbbb22..d8386d1 100644 (file)
@@ -21,7 +21,7 @@ class ReplicateTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $value) {
             $list = replicate($n, $value);
 
-            return length($list) === $n;
+            $this->assertEquals($n, length($list));
         });
     }
 
@@ -33,7 +33,7 @@ class ReplicateTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $value) {
             $list = replicate($n, $value);
 
-            return length(filter(eql($value), $list)) === $n;
+            $this->assertEquals($n, length(filter(eql($value), $list)));
         });
     }
 }
index 0c5e245..f2af019 100644 (file)
@@ -60,8 +60,8 @@ class UnzipTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $x, $y) {
             [$xs, $ys] = unzip(repeat([$x, $y]));
 
-            return length(filter(eql($x), take($n, $xs))) === $n
-                && length(filter(eql($y), take($n, $ys))) === $n;
+            $this->assertEquals($n, length(filter(eql($x), take($n, $xs))));
+            $this->assertEquals($n, length(filter(eql($y), take($n, $ys))));
         });
     }
 }
index 9670f89..471f7c1 100644 (file)
@@ -85,7 +85,7 @@ class ZipTest extends \PHPUnit\Framework\TestCase
         )->then(function ($n, $a, $b) {
             $list = take($n, zip(repeat($a), repeat($b)));
 
-            return length(filter(eql([$a, $b]), $list)) === $n;
+            $this->assertEquals($n, length(filter(eql([$a, $b]), $list)));
         });
     }
 }
index b36e345..29e7d43 100644 (file)
@@ -17,7 +17,8 @@ class MatchTest extends \PHPUnit\Framework\TestCase
         $value,
         $expectedMessage
     ) {
-        $this->setExpectedException(PatternNotMatchedError::class, $expectedMessage);
+        $this->expectException(PatternNotMatchedError::class);
+        $this->expectExceptionMessage($expectedMessage);
 
         match($patterns, $value);
     }