| @@ 140-150 (lines=11) @@ | ||
| 137 | $collection->size()->shouldReturn(6); |
|
| 138 | } |
|
| 139 | ||
| 140 | function it_can_map() |
|
| 141 | { |
|
| 142 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 143 | ||
| 144 | $this |
|
| 145 | ->map(function ($item) { |
|
| 146 | return $item + 1; |
|
| 147 | }) |
|
| 148 | ->toArray() |
|
| 149 | ->shouldReturn([2, 4, 4, 3]); |
|
| 150 | } |
|
| 151 | ||
| 152 | function it_can_reduce() |
|
| 153 | { |
|
| @@ 464-478 (lines=15) @@ | ||
| 461 | ->shouldReturn(false); |
|
| 462 | } |
|
| 463 | ||
| 464 | function it_can_reverse() |
|
| 465 | { |
|
| 466 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 467 | ||
| 468 | $this |
|
| 469 | ->reverse() |
|
| 470 | ->toArray() |
|
| 471 | ->shouldReturn([ |
|
| 472 | 3 => 2, |
|
| 473 | 2 => 3, |
|
| 474 | 1 => 3, |
|
| 475 | 0 => 1, |
|
| 476 | ]) |
|
| 477 | ; |
|
| 478 | } |
|
| 479 | ||
| 480 | function it_can_reduce_from_right() |
|
| 481 | { |
|
| @@ 615-624 (lines=10) @@ | ||
| 612 | ->shouldReturn([1, 3, 3, 2, 1, 3, 3, 2]); |
|
| 613 | } |
|
| 614 | ||
| 615 | function it_can_prepend_item() |
|
| 616 | { |
|
| 617 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 618 | ||
| 619 | $this |
|
| 620 | ->prepend(1) |
|
| 621 | ->values() |
|
| 622 | ->toArray() |
|
| 623 | ->shouldReturn([1, 1, 3, 3, 2]); |
|
| 624 | } |
|
| 625 | ||
| 626 | function it_can_prepend_item_with_key() |
|
| 627 | { |
|
| @@ 636-645 (lines=10) @@ | ||
| 633 | ->shouldReturn(['a' => 1, 0 => 1, 1 => 3, 2 => 3, 3 => 2]); |
|
| 634 | } |
|
| 635 | ||
| 636 | function it_can_append_item() |
|
| 637 | { |
|
| 638 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 639 | ||
| 640 | $this |
|
| 641 | ->append(1) |
|
| 642 | ->values() |
|
| 643 | ->toArray() |
|
| 644 | ->shouldReturn([1, 3, 3, 2, 1]); |
|
| 645 | } |
|
| 646 | ||
| 647 | function it_can_append_item_with_key() |
|
| 648 | { |
|
| @@ 746-754 (lines=9) @@ | ||
| 743 | $s2->second()->toArray()->shouldBe([1 => 3, 2 => 3, 3 => 2]); |
|
| 744 | } |
|
| 745 | ||
| 746 | function it_can_replace_items_by_items_from_another_collection() |
|
| 747 | { |
|
| 748 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 749 | ||
| 750 | $this |
|
| 751 | ->replace([3 => 'a']) |
|
| 752 | ->toArray() |
|
| 753 | ->shouldReturn([1, 'a', 'a', 2]); |
|
| 754 | } |
|
| 755 | ||
| 756 | function it_can_get_reduction_steps() |
|
| 757 | { |
|
| @@ 756-769 (lines=14) @@ | ||
| 753 | ->shouldReturn([1, 'a', 'a', 2]); |
|
| 754 | } |
|
| 755 | ||
| 756 | function it_can_get_reduction_steps() |
|
| 757 | { |
|
| 758 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 759 | ||
| 760 | $this |
|
| 761 | ->reductions( |
|
| 762 | function ($tmp, $i) { |
|
| 763 | return $tmp + $i; |
|
| 764 | }, |
|
| 765 | 0 |
|
| 766 | ) |
|
| 767 | ->toArray() |
|
| 768 | ->shouldReturn([0, 1, 4, 7, 9]); |
|
| 769 | } |
|
| 770 | ||
| 771 | function it_can_return_every_nth_item() |
|
| 772 | { |
|