1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Component\Core\Distributor; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Component\Core\Distributor\IntegerDistributorInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Mateusz Zalewski <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class IntegerDistributorSpec extends ObjectBehavior |
21
|
|
|
{ |
22
|
|
|
function it_is_initializable() |
23
|
|
|
{ |
24
|
|
|
$this->shouldHaveType('Sylius\Component\Core\Distributor\IntegerDistributor'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
function it_implements_integer_distributor_interface() |
28
|
|
|
{ |
29
|
|
|
$this->shouldImplement(IntegerDistributorInterface::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function it_distributes_simple_integers() |
33
|
|
|
{ |
34
|
|
|
$this->distribute(0, 4)->shouldReturn([0, 0, 0, 0]); |
35
|
|
|
$this->distribute(1000, 4)->shouldReturn([250, 250, 250, 250]); |
36
|
|
|
$this->distribute(-1000, 4)->shouldReturn([-250, -250, -250, -250]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_distributes_integers_that_cannot_be_split_equally() |
40
|
|
|
{ |
41
|
|
|
$this->distribute(1000, 3)->shouldReturn([334, 333, 333]); |
42
|
|
|
$this->distribute(-1000, 3)->shouldReturn([-334, -333, -333]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_throws_exception_if_number_of_targets_is_not_integer_or_below_1() |
46
|
|
|
{ |
47
|
|
|
$this->shouldThrow(new \InvalidArgumentException('Number of targets must be an integer, bigger than 0.'))->during('distribute', [1000, 'test']); |
48
|
|
|
$this->shouldThrow(new \InvalidArgumentException('Number of targets must be an integer, bigger than 0.'))->during('distribute', [1000, 0]); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|