Improve code coverage for Sum
authorwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 21:12:15 +0000 (22:12 +0100)
committerwidmogrod <widmogrod@gmail.com>
Thu, 21 Dec 2017 21:12:15 +0000 (22:12 +0100)
test/Primitive/SumTest.php

index 79535e2..e750ad7 100644 (file)
@@ -5,12 +5,13 @@ namespace test\Primitive;
 use Widmogrod\Functional as f;
 use Widmogrod\Helpful\MonoidLaws;
 use Widmogrod\Helpful\SetoidLaws;
+use Widmogrod\Primitive\Product;
 use Widmogrod\Primitive\Sum;
 
 class SumTest extends \PHPUnit\Framework\TestCase
 {
     /**
-     * @dataProvider provideSetoidLaws
+     * @dataProvider provideRandomizedData
      */
     public function test_it_should_obay_setoid_laws(
         $a,
@@ -26,7 +27,7 @@ class SumTest extends \PHPUnit\Framework\TestCase
     }
 
     /**
-     * @dataProvider provideSetoidLaws
+     * @dataProvider provideRandomizedData
      */
     public function test_it_should_obay_monoid_laws(
         $a,
@@ -41,12 +42,22 @@ class SumTest extends \PHPUnit\Framework\TestCase
         );
     }
 
+    /**
+     * @expectedException \Widmogrod\Primitive\TypeMismatchError
+     * @expectedExceptionMessage Expected type is Widmogrod\Primitive\Sum but given Widmogrod\Primitive\Product
+     * @dataProvider provideRandomizedData
+     */
+    public function test_it_should_reject_concat_on_different_type(Sum $a)
+    {
+        $a->concat(Product::of(1));
+    }
+
     private function randomize()
     {
         return Sum::of(random_int(-100000000, 100000000));
     }
 
-    public function provideSetoidLaws()
+    public function provideRandomizedData()
     {
         return array_map(function () {
             return [