1<?php
2
3/**
4 * Hoa
5 *
6 *
7 * @license
8 *
9 * New BSD License
10 *
11 * Copyright © 2007-2017, Hoa community. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *     * Redistributions of source code must retain the above copyright
16 *       notice, this list of conditions and the following disclaimer.
17 *     * Redistributions in binary form must reproduce the above copyright
18 *       notice, this list of conditions and the following disclaimer in the
19 *       documentation and/or other materials provided with the distribution.
20 *     * Neither the name of the Hoa nor the names of its contributors may be
21 *       used to endorse or promote products derived from this software without
22 *       specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37namespace Hoa\Math\Test\Unit\Combinatorics\Combination;
38
39use Hoa\Math\Combinatorics\Combination\CartesianProduct as CUT;
40use Hoa\Test;
41
42/**
43 * Class \Hoa\Math\Test\Unit\Combinatorics\Combination\CartesianProduct.
44 *
45 * Test suite of the cartesian product.
46 *
47 * @copyright  Copyright © 2007-2017 Hoa community
48 * @license    New BSD License
49 */
50class CartesianProduct extends Test\Unit\Suite
51{
52    public function case_empty()
53    {
54        $this
55            ->given($iterator = new CUT([]))
56            ->when($result = iterator_to_array($iterator))
57            ->then
58                ->array($result)
59                    ->isEqualTo([[null]]);
60    }
61
62    public function case_X()
63    {
64        $this
65            ->given($iterator = new CUT([1, 2, 3]))
66            ->when($result = iterator_to_array($iterator))
67            ->then
68                ->array($result)
69                    ->isEqualTo([
70                        [1],
71                        [2],
72                        [3]
73                    ]);
74    }
75
76    public function case_X_Y()
77    {
78        $this
79            ->given($iterator = new CUT([1, 2, 3], [4, 5, 6]))
80            ->when($result = iterator_to_array($iterator))
81            ->then
82                ->array($result)
83                    ->isEqualTo([
84                        [1, 4],
85                        [2, 4],
86                        [3, 4],
87
88                        [1, 5],
89                        [2, 5],
90                        [3, 5],
91
92                        [1, 6],
93                        [2, 6],
94                        [3, 6]
95                    ]);
96    }
97
98    public function case_X_Y_Z()
99    {
100        $this
101            ->given($iterator = new CUT([1, 2, 3], [4, 5, 6], [7, 8, 9]))
102            ->when($result = iterator_to_array($iterator))
103            ->then
104                ->array($result)
105                    ->isEqualTo([
106                        [1, 4, 7],
107                        [2, 4, 7],
108                        [3, 4, 7],
109                        [1, 5, 7],
110                        [2, 5, 7],
111                        [3, 5, 7],
112                        [1, 6, 7],
113                        [2, 6, 7],
114                        [3, 6, 7],
115
116                        [1, 4, 8],
117                        [2, 4, 8],
118                        [3, 4, 8],
119                        [1, 5, 8],
120                        [2, 5, 8],
121                        [3, 5, 8],
122                        [1, 6, 8],
123                        [2, 6, 8],
124                        [3, 6, 8],
125
126                        [1, 4, 9],
127                        [2, 4, 9],
128                        [3, 4, 9],
129                        [1, 5, 9],
130                        [2, 5, 9],
131                        [3, 5, 9],
132                        [1, 6, 9],
133                        [2, 6, 9],
134                        [3, 6, 9]
135                    ]);
136    }
137}
138