Skip to content

Commit ed2167f

Browse files
authored
Merge pull request #84 from widmogrod/feature/fix-io
Feature/fix io
2 parents 4b2d824 + 002117f commit ed2167f

File tree

10 files changed

+146
-190
lines changed

10 files changed

+146
-190
lines changed

src/Monad/IO/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function getArgs()
175175
));
176176
}
177177

178-
return f\tail($_SERVER['argv']);
178+
return f\tail(f\fromIterable($_SERVER['argv']));
179179
});
180180
}
181181

src/Primitive/Stringg.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function concat(FantasyLand\Semigroup $value): FantasyLand\Semigroup
4444
public function equals($other): bool
4545
{
4646
return $other instanceof self
47-
? $this->extract() === $other->extract()
47+
? $this->value === $other->value
4848
: false;
4949
}
5050
}

test/Monad/EitherTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EitherTest extends \PHPUnit\Framework\TestCase
2222
public function test_if_maybe_monad_obeys_the_laws($return, $f, $g, $x)
2323
{
2424
MonadLaws::test(
25-
f\curryN(3, [$this, 'assertEquals']),
25+
[$this, 'assertEquals'],
2626
f\curryN(1, $return),
2727
$f,
2828
$g,
@@ -69,7 +69,7 @@ public function test_it_should_obey_applicative_laws(
6969
$x
7070
) {
7171
ApplicativeLaws::test(
72-
f\curryN(3, [$this, 'assertEquals']),
72+
[$this, 'assertEquals'],
7373
f\curryN(1, $pure),
7474
$u,
7575
$v,
@@ -126,7 +126,7 @@ public function test_it_should_obey_functor_laws(
126126
Functor $x
127127
) {
128128
FunctorLaws::test(
129-
f\curryN(3, [$this, 'assertEquals']),
129+
[$this, 'assertEquals'],
130130
$f,
131131
$g,
132132
$x

test/Monad/IdentityTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IdentityTest extends \PHPUnit\Framework\TestCase
2020
public function test_if_identity_monad_obeys_the_laws($f, $g, $x)
2121
{
2222
MonadLaws::test(
23-
f\curryN(3, [$this, 'assertEquals']),
23+
[$this, 'assertEquals'],
2424
f\curryN(1, Identity::of),
2525
$f,
2626
$g,
@@ -57,7 +57,7 @@ public function test_it_should_obey_applicative_laws(
5757
$x
5858
) {
5959
ApplicativeLaws::test(
60-
f\curryN(3, [$this, 'assertEquals']),
60+
[$this, 'assertEquals'],
6161
f\curryN(1, Identity::of),
6262
$u,
6363
$v,
@@ -97,7 +97,7 @@ public function test_it_should_obey_functor_laws(
9797
Functor $x
9898
) {
9999
FunctorLaws::test(
100-
f\curryN(3, [$this, 'assertEquals']),
100+
[$this, 'assertEquals'],
101101
$f,
102102
$g,
103103
$x

test/Monad/MaybeTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MaybeTest extends \PHPUnit\Framework\TestCase
2424
public function test_if_maybe_monad_obeys_the_laws($return, $f, $g, $x)
2525
{
2626
MonadLaws::test(
27-
f\curryN(3, [$this, 'assertEquals']),
27+
[$this, 'assertEquals'],
2828
f\curryN(1, $return),
2929
$f,
3030
$g,
@@ -70,7 +70,7 @@ public function test_it_should_obey_applicative_laws(
7070
$x
7171
) {
7272
ApplicativeLaws::test(
73-
f\curryN(3, [$this, 'assertEquals']),
73+
[$this, 'assertEquals'],
7474
f\curryN(1, $pure),
7575
$u,
7676
$v,
@@ -124,7 +124,7 @@ public function provideApplicativeTestData()
124124
public function test_it_should_obey_monoid_laws($x, $y, $z)
125125
{
126126
MonoidLaws::test(
127-
f\curryN(3, [$this, 'assertEquals']),
127+
[$this, 'assertEquals'],
128128
$x,
129129
$y,
130130
$z
@@ -166,7 +166,7 @@ public function test_it_should_obey_functor_laws(
166166
Functor $x
167167
) {
168168
FunctorLaws::test(
169-
f\curryN(3, [$this, 'assertEquals']),
169+
[$this, 'assertEquals'],
170170
$f,
171171
$g,
172172
$x

test/Primitive/ListtTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ListtTest extends \PHPUnit\Framework\TestCase
2828
public function test_if_list_obeys_the_laws($f, $g, $x)
2929
{
3030
MonadLaws::test(
31-
f\curryN(3, [$this, 'assertEquals']),
31+
[$this, 'assertEquals'],
3232
f\curryN(1, fromValue),
3333
$f,
3434
$g,
@@ -66,7 +66,7 @@ public function test_it_should_obey_applicative_laws(
6666
$x
6767
) {
6868
ApplicativeLaws::test(
69-
f\curryN(3, [$this, 'assertEquals']),
69+
[$this, 'assertEquals'],
7070
f\curryN(1, $pure),
7171
$u,
7272
$v,
@@ -107,7 +107,7 @@ public function test_it_should_obey_functor_laws(
107107
Functor $x
108108
) {
109109
FunctorLaws::test(
110-
f\curryN(3, [$this, 'assertEquals']),
110+
[$this, 'assertEquals'],
111111
$f,
112112
$g,
113113
$x
@@ -135,7 +135,7 @@ public function provideFunctorTestData()
135135
public function test_it_should_obey_monoid_laws(Monoid $x, Monoid $y, Monoid $z)
136136
{
137137
MonoidLaws::test(
138-
f\curryN(3, [$this, 'assertEquals']),
138+
[$this, 'assertEquals'],
139139
$x,
140140
$y,
141141
$z

test/Primitive/NumTest.php

+16-29
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,28 @@
44

55
namespace test\Primitive;
66

7-
use Widmogrod\Functional as f;
7+
use Eris\TestTrait;
8+
use Eris\Generator;
89
use Widmogrod\Helpful\SetoidLaws;
910
use Widmogrod\Primitive\Num;
1011

1112
class NumTest extends \PHPUnit\Framework\TestCase
1213
{
13-
/**
14-
* @dataProvider provideSetoidLaws
15-
*/
16-
public function test_it_should_obay_setoid_laws(
17-
$a,
18-
$b,
19-
$c
20-
) {
21-
SetoidLaws::test(
22-
f\curryN(3, [$this, 'assertEquals']),
23-
$a,
24-
$b,
25-
$c
26-
);
27-
}
28-
29-
private function randomize()
30-
{
31-
return Num::of(random_int(-100000000, 100000000));
32-
}
14+
use TestTrait;
3315

34-
public function provideSetoidLaws()
16+
public function test_it_should_obay_setoid_laws()
3517
{
36-
return array_map(function () {
37-
return [
38-
$this->randomize(),
39-
$this->randomize(),
40-
$this->randomize(),
41-
];
42-
}, array_fill(0, 50, null));
18+
$this->forAll(
19+
Generator\choose(0, 1000),
20+
Generator\choose(1000, 4000),
21+
Generator\choose(4000, 100000)
22+
)->then(function (int $x, int $y, int $z) {
23+
SetoidLaws::test(
24+
[$this, 'assertEquals'],
25+
Num::of($x),
26+
Num::of($y),
27+
Num::of($z)
28+
);
29+
});
4330
}
4431
}

test/Primitive/ProductTest.php

+36-50
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace test\Primitive;
66

7+
use Eris\Generator;
78
use Eris\TestTrait;
8-
use Widmogrod\Functional as f;
99
use Widmogrod\Helpful\MonoidLaws;
1010
use Widmogrod\Helpful\SetoidLaws;
1111
use Widmogrod\Primitive\Product;
@@ -15,63 +15,49 @@ class ProductTest extends \PHPUnit\Framework\TestCase
1515
{
1616
use TestTrait;
1717

18-
/**
19-
* @dataProvider provideSetoidLaws
20-
*/
21-
public function test_it_should_obay_setoid_laws(
22-
$a,
23-
$b,
24-
$c
25-
) {
26-
SetoidLaws::test(
27-
f\curryN(3, [$this, 'assertEquals']),
28-
$a,
29-
$b,
30-
$c
31-
);
18+
public function test_it_should_obay_setoid_laws()
19+
{
20+
$this->forAll(
21+
Generator\choose(0, 1000),
22+
Generator\choose(1000, 4000),
23+
Generator\choose(4000, 100000)
24+
)->then(function (int $x, int $y, int $z) {
25+
SetoidLaws::test(
26+
[$this, 'assertEquals'],
27+
Product::of($x),
28+
Product::of($y),
29+
Product::of($z)
30+
);
31+
});
3232
}
3333

34-
/**
35-
* @dataProvider provideSetoidLaws
36-
*/
37-
public function test_it_should_obay_monoid_laws(
38-
$a,
39-
$b,
40-
$c
41-
) {
42-
MonoidLaws::test(
43-
f\curryN(3, [$this, 'assertEquals']),
44-
$a,
45-
$b,
46-
$c
47-
);
34+
public function test_it_should_obay_monoid_laws()
35+
{
36+
$this->forAll(
37+
Generator\choose(0, 1000),
38+
Generator\choose(1000, 4000),
39+
Generator\choose(4000, 100000)
40+
)->then(function (int $x, int $y, int $z) {
41+
MonoidLaws::test(
42+
[$this, 'assertEquals'],
43+
Product::of($x),
44+
Product::of($y),
45+
Product::of($z)
46+
);
47+
});
4848
}
4949

5050
/**
5151
* @expectedException \Widmogrod\Primitive\TypeMismatchError
5252
* @expectedExceptionMessage Expected type is Widmogrod\Primitive\Product but given Widmogrod\Primitive\Stringg
53-
* @dataProvider provideSetoidLaws
5453
*/
55-
public function test_it_should_reject_concat_on_different_type(Product $a)
56-
{
57-
$a->concat(Stringg::of("a"));
58-
}
59-
60-
private function randomize()
61-
{
62-
usleep(100);
63-
64-
return Product::of(random_int(-1000, 1000));
65-
}
66-
67-
public function provideSetoidLaws()
54+
public function test_it_should_reject_concat_on_different_type()
6855
{
69-
return array_map(function () {
70-
return [
71-
$this->randomize(),
72-
$this->randomize(),
73-
$this->randomize(),
74-
];
75-
}, array_fill(0, 50, null));
56+
$this->forAll(
57+
Generator\int(),
58+
Generator\string()
59+
)->then(function (int $x, string $y) {
60+
Product::of($x)->concat(Stringg::of($y));
61+
});
7662
}
7763
}

0 commit comments

Comments
 (0)