SortedArrayHashMapTests::testRemoveAt()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 22

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Collections\Tests\Units\ArrayCollection;
11
12
use Cubiche\Core\Collections\ArrayCollection\SortedArrayHashMap;
13
use Cubiche\Core\Comparable\Comparator;
14
15
/**
16
 * SortedArrayHashMapTests class.
17
 *
18
 * @method protected ArrayHashMapInterface randomCollection($size = null)
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class SortedArrayHashMapTests extends ArrayHashMapTests
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function emptyCollection()
28
    {
29
        return new SortedArrayHashMap([], $this->comparator());
30
    }
31
32
    /*
33
     * Test create.
34
     */
35 View Code Duplication
    public function testCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $this
38
            ->given($comparator = new Comparator())
39
            ->and($collection = new SortedArrayHashMap($this->randomValues(10)))
40
            ->and($reverseComparator = $comparator->reverse())
41
            ->then()
42
                ->hashmap($collection)
43
                    ->isSortedUsing($comparator)
44
                    ->isNotSortedUsing($reverseComparator)
45
        ;
46
    }
47
48
    /**
49
     * Test set.
50
     */
51
    public function testSet()
52
    {
53
        $this
54
            ->given($collection = $this->randomCollection())
55
            ->and($unique = $this->uniqueValue())
56
            ->and($comparator = $this->comparator())
57
            ->then()
58
                ->hashmap($collection)
59
                    ->notContainsKey('foo')
60
                    ->isSortedUsing($comparator)
61
            ->and()
62
            ->when($collection->set('foo', $unique))
63
            ->then()
64
                ->hashmap($collection)
65
                    ->containsKey('foo')
66
                    ->isSortedUsing($comparator)
67
        ;
68
    }
69
70
    /*
71
     * Test removeAt.
72
     */
73 View Code Duplication
    public function testRemoveAt()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $this
76
            ->given(
77
                $unique = $this->uniqueValue(),
78
                $collection = $this->emptyCollection()
79
            )
80
            ->and($comparator = $this->comparator())
81
            ->then()
82
                ->hashmap($collection)
83
                    ->notContainsKey('foo')
84
                    ->isSortedUsing($comparator)
85
            ->and()
86
            ->when($collection->set('foo', $unique))
87
            ->then()
88
                ->hashmap($collection)
89
                    ->containsKey('foo')
90
            ->and()
91
            ->when($element = $collection->removeAt('foo'))
92
            ->then()
93
                ->variable($element)
94
                    ->isEqualTo($unique)
95
                ->hashmap($collection)
96
                    ->isSortedUsing($comparator)
97
        ;
98
    }
99
100
    /*
101
     * Test sort.
102
     */
103 View Code Duplication
    public function testSort()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $this
106
            ->given(
107
                $comparator = $this->comparator(),
108
                $reverseComparator = $comparator->reverse(),
109
                $collection = $this->randomCollection()
110
            )
111
            ->when($collection->sort($reverseComparator))
112
            ->then()
113
                ->hashmap($collection)
114
                    ->isSortedUsing($reverseComparator)
115
            ->and
116
            ->when($collection->sort())
117
            ->then()
118
                ->hashmap($collection)
119
                    ->isSortedUsing($reverseComparator)
120
                ->hashmap($collection)
121
                    ->isNotSortedUsing($comparator)
122
        ;
123
    }
124
}
125