Hoa central
Demultiplexer.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Iterator\Test\Unit;
38 
39 use Hoa\Iterator as LUT;
40 use Hoa\Test;
41 
51 {
52  public function case_classic()
53  {
54  $this
55  ->given(
56  $counter = new LUT\Counter(0, 10, 1),
57  $multiple = new LUT\Multiple(),
58  $multiple->attachIterator($counter),
59  $multiple->attachIterator(clone $counter),
60  $demultiplexer = new LUT\Demultiplexer(
61  $multiple,
62  function ($current) {
63  return $current[0] * $current[1];
64  }
65  )
66  )
67  ->when($result = iterator_to_array($demultiplexer, false))
68  ->then
69  ->array($result)
70  ->isEqualTo([
71  0,
72  1,
73  4,
74  9,
75  16,
76  25,
77  36,
78  49,
79  64,
80  81
81  ]);
82  }
83 
84  public function case_associative_keys()
85  {
86  $this
87  ->given(
88  $counter = new LUT\Counter(0, 10, 1),
89  $multiple = new LUT\Multiple(
90  LUT\Multiple::MIT_NEED_ANY
91  | LUT\Multiple::MIT_KEYS_ASSOC
92  ),
93  $multiple->attachIterator($counter, 'one'),
94  $multiple->attachIterator(clone $counter, 'two'),
95  $demultiplexer = new LUT\Demultiplexer(
96  $multiple,
97  function ($current) {
98  return $current['one'] * $current['two'];
99  }
100  )
101  )
102  ->when($result = iterator_to_array($demultiplexer, false))
103  ->then
104  ->array($result)
105  ->isEqualTo([
106  0,
107  1,
108  4,
109  9,
110  16,
111  25,
112  36,
113  49,
114  64,
115  81
116  ]);
117  }
118 }