Test Failed
Pull Request — master (#6)
by Andrew
02:41
created

testConsolidateVerboseWithMaxRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 19
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace AndrewAndante\SubMuncher\Test;
4
5
use AndrewAndante\SubMuncher\SubMuncher;
6
7
class SubMuncherVerboseTest extends \PHPUnit_Framework_TestCase
8
{
9 View Code Duplication
    public function testConsolidateVerbose()
1 ignored issue
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...
10
    {
11
        $this->assertEquals(
12
            [
13
                'consolidated_subnets' => ['10.10.10.0/31'],
14
                'initial_IPs' => ['10.10.10.0', '10.10.10.1'],
15
                'total_IPs' => ['10.10.10.0', '10.10.10.1'],
16
            ],
17
            SubMuncher::consolidate_verbose(['10.10.10.0', '10.10.10.1'])
18
        );
19
        $this->assertEquals(
20
            [
21
                'consolidated_subnets' => ['10.10.10.0/31', '10.10.10.2/32'],
22
                'initial_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.2'],
23
                'total_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.2'],
24
            ],
25
            SubMuncher::consolidate_verbose(['10.10.10.0', '10.10.10.1', '10.10.10.2'])
26
        );
27
        $longIPList = [
28
            '10.10.10.0',
29
            '10.10.10.1',
30
            '10.10.10.2',
31
            '100.10.10.0',
32
            '100.10.10.1',
33
            '100.10.10.2',
34
            '100.10.10.3',
35
            '100.10.10.4',
36
            '100.10.10.5'
37
        ];
38
        $results = SubMuncher::consolidate_verbose($longIPList);
39
        $this->assertEquals($results['initial_IPs'], $results['total_IPs']);
40
        $this->assertEquals(
41
            ['10.10.10.0/31', '10.10.10.2/32', '100.10.10.0/30', '100.10.10.4/31'],
42
            $results['consolidated_subnets']
43
        );
44
    }
45
46
    public function testConsolidateVerboseWithMaxRules()
47
    {
48
        $this->assertEquals(
49
            [
50
                'consolidated_subnets' => ['10.10.10.0/31'],
51
                'initial_IPs' => ['10.10.10.0', '10.10.10.1'],
52
                'total_IPs' => ['10.10.10.0', '10.10.10.1'],
53
            ],
54
            SubMuncher::consolidate_verbose(['10.10.10.0', '10.10.10.1'], 1)
55
        );
56
        $this->assertEquals(
57
            [
58
                'consolidated_subnets' => ['10.10.10.0/30'],
59
                'initial_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.3'],
60
                'total_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.2', '10.10.10.3'],
61
            ],
62
            SubMuncher::consolidate_verbose(['10.10.10.0', '10.10.10.1', '10.10.10.3'], 1)
63
        );
64
    }
65
66 View Code Duplication
    public function testConsolidateSubnetsVerbose()
1 ignored issue
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...
67
    {
68
        $this->assertEquals(
69
            [
70
                'consolidated_subnets' => ['10.10.10.0/31'],
71
                'initial_IPs' => ['10.10.10.0', '10.10.10.1'],
72
                'total_IPs' => ['10.10.10.0', '10.10.10.1'],
73
            ],
74
            SubMuncher::consolidate_subnets_verbose(['10.10.10.0/32', '10.10.10.1/32'])
75
        );
76
        $this->assertEquals(
77
            [
78
                'consolidated_subnets' => ['10.10.10.0/30'],
79
                'initial_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.2', '10.10.10.3'],
80
                'total_IPs' => ['10.10.10.0', '10.10.10.1', '10.10.10.2', '10.10.10.3'],
81
            ],
82
            SubMuncher::consolidate_subnets_verbose(['10.10.10.0/31', '10.10.10.2/31'])
83
        );
84
85
        $longSubnetList = [
86
            '10.10.10.0/32',
87
            '10.10.10.1/32',
88
            '10.10.10.2/32',
89
            '100.10.10.0/32',
90
            '100.10.10.1/32',
91
            '100.10.10.2/32',
92
            '100.10.10.3/32',
93
            '100.10.10.4/31',
94
        ];
95
        $result = SubMuncher::consolidate_subnets_verbose($longSubnetList);
96
97
        $this->assertEquals($result['initial_IPs'], $result['total_IPs']);
98
        $this->assertEquals(
99
            ['10.10.10.0/31', '10.10.10.2/32', '100.10.10.0/30', '100.10.10.4/31'],
100
            $result['consolidated_subnets']
101
        );
102
    }
103
104
    public function testConsolidateSubnetsVerboseWithMaxRules()
105
    {
106
        $initialIPs = [
107
            '10.10.10.0',
108
            '10.10.10.1',
109
            '10.10.10.2',
110
            '100.10.10.0',
111
            '100.10.10.1',
112
            '100.10.10.2',
113
            '100.10.10.3',
114
            '100.10.10.4',
115
            '100.10.10.5',
116
        ];
117
        $initialSubnets = [
118
            '10.10.10.0/32',
119
            '10.10.10.1/32',
120
            '10.10.10.2/32',
121
            '100.10.10.0/32',
122
            '100.10.10.1/32',
123
            '100.10.10.2/32',
124
            '100.10.10.3/32',
125
            '100.10.10.4/31',
126
        ];
127
128
        $this->assertEquals(
129
            [
130
                'consolidated_subnets' => ['10.10.10.0/31', '10.10.10.2/32', '100.10.10.0/30', '100.10.10.4/31'],
131
                'initial_IPs' => $initialIPs,
132
                'total_IPs' => $initialIPs
133
            ],
134
            SubMuncher::consolidate_subnets_verbose($initialSubnets, 4)
135
        );
136
        $this->assertEquals(
137
            [
138
                'consolidated_subnets' => ['10.10.10.0/30', '100.10.10.0/30', '100.10.10.4/31'],
139
                'initial_IPs' => $initialIPs,
140
                'total_IPs' => [
141
                    '10.10.10.0',
142
                    '10.10.10.1',
143
                    '10.10.10.2',
144
                    '10.10.10.3',
145
                    '100.10.10.0',
146
                    '100.10.10.1',
147
                    '100.10.10.2',
148
                    '100.10.10.3',
149
                    '100.10.10.4',
150
                    '100.10.10.5',
151
                ]
152
            ],
153
            SubMuncher::consolidate_subnets_verbose($initialSubnets, 3)
154
        );
155
    }
156
}
157