-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathip_test.go
294 lines (244 loc) · 7.72 KB
/
ip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package ipsubnet
import "testing"
type TestCase struct {
ip string
subnet int
numberIPAddresses int
numberAddressableHosts int
ipAddressRange []string
networkSize int
broadCastAddress string
ipAddressQuards []int
ipAddressHex string
ipAddressBinary string
subnetMask string
subnetMaskQuards []int
subnetMaskHex string
subnetMaskBinary string
networkPortion string
networkPortionQuards []int
networkPortionHex string
networkPortionBinary string
hostPortion string
hostPortionQuards []int
hostPortionHex string
hostPortionBinary string
}
func builder() TestCase {
test := TestCase{}
test.ip = "192.168.112.203"
test.subnet = 23
test.numberIPAddresses = 512
test.numberAddressableHosts = 510
test.ipAddressRange = []string{"192.168.112.0", "192.168.113.255"}
test.networkSize = 23
test.broadCastAddress = "192.168.113.255"
test.ipAddressQuards = []int{192, 168, 112, 203}
test.ipAddressHex = "C0A870CB"
test.ipAddressBinary = "11000000101010000111000011001011"
// Subnet
test.subnetMask = "255.255.254.0"
test.subnetMaskQuards = []int{255, 255, 254, 0}
test.subnetMaskHex = "FFFFFE00"
test.subnetMaskBinary = "11111111111111111111111000000000"
// Network Portion
test.networkPortion = "192.168.112.0"
test.networkPortionQuards = []int{192, 168, 112, 0}
test.networkPortionHex = "C0A87000"
test.networkPortionBinary = "11000000101010000111000000000000"
// Network Portion
test.hostPortion = "0.0.0.203"
test.hostPortionQuards = []int{0, 0, 0, 203}
test.hostPortionHex = "000000CB"
test.hostPortionBinary = "00000000000000000000000011001011"
return test
}
func ip() *Ip {
return SubnetCalculator(builder().ip, builder().subnet)
}
func TestGetNumberIPAddresses(t *testing.T) {
wants := builder().numberIPAddresses
got := ip().GetNumberIPAddresses()
if wants != got {
t.Errorf("GetNumberIPAddresses Failed: Wants %v Got %v", wants, got)
}
}
func TestGetNumberAddressableHosts(t *testing.T) {
wants := builder().numberAddressableHosts
got := ip().GetNumberAddressableHosts()
if wants != got {
t.Errorf("GetNumberAddressableHosts Failed: Wants %v Got %v", wants, got)
}
}
func TestGetIPAddressRange(t *testing.T) {
wants := builder().ipAddressRange
got := ip().GetIPAddressRange()
if wants[0] != got[0] {
t.Errorf("First Value of GetIPAddressRange Failed: Wants %v Got %v", wants[0], got[0])
}
if wants[1] != got[1] {
t.Errorf("First Value of GetIPAddressRange Failed: Wants %v Got %v", wants[1], got[1])
}
}
func TestGetNetworSize(t *testing.T) {
wants := builder().networkSize
got := ip().GetNetworkSize()
if wants != got {
t.Errorf("GetNetworkSize Failed: Wants %v Got %v", wants, got)
}
}
func TestGetBroadcastAddress(t *testing.T) {
wants := builder().broadCastAddress
got := ip().GetBroadcastAddress()
if wants != got {
t.Errorf("GetBroadcastAdress Failed: Wants %v Got %v", wants, got)
}
}
func TestGetIPAddress(t *testing.T) {
wants := builder().ip
got := ip().GetIPAddress()
if wants != got {
t.Errorf("GetIPAddress Failed: Wants %v Got %v", wants, got)
}
}
func TestGetIPAddressQuads(t *testing.T) {
wants := builder().ipAddressQuards
got := ip().GetIPAddressQuads()
if got[0] != wants[0] {
t.Errorf("First Value of GetIPAddressQuards Failed: Wants %v Got %v", wants[0], got[0])
}
if got[1] != wants[1] {
t.Errorf("Second Value of GetIPAddressQuards Failed: Wants %v Got %v", wants[1], got[1])
}
if got[2] != wants[2] {
t.Errorf("Third Value of GetIPAddressQuards Failed: Wants %v Got %v", wants[2], got[2])
}
if got[3] != wants[3] {
t.Errorf("Fourth Value of GetIPAddressQuards Failed: Wants %v Got %v", wants[3], got[3])
}
}
func TestGetIPAddressHex(t *testing.T) {
wants := builder().ipAddressHex
got := ip().GetIPAddressHex()
if wants != got {
t.Errorf("GetIpAddressHex Failed: Wants %v Got %v", wants, got)
}
}
func TestGetIPAddressBinary(t *testing.T) {
wants := builder().ipAddressBinary
got := ip().GetIPAddressBinary()
if wants != got {
t.Errorf("GetIpAddressBinary Failed: Wants %v Got %v", wants, got)
}
}
func TestGetSubnetMask(t *testing.T) {
wants := builder().subnetMask
got := ip().GetSubnetMask()
if wants != got {
t.Errorf("GetSubnetMask Failed: Wants %v Got %v", wants, got)
}
}
func TestGetSubnetMaskQuards(t *testing.T) {
wants := builder().subnetMaskQuards
got := ip().GetSubnetMaskQuards()
if got[0] != wants[0] {
t.Errorf("First Value of GetSubnetMaskQuards Failed: Wants %v Got %v", wants[0], got[0])
}
if got[1] != wants[1] {
t.Errorf("Second Value of GetSubnetMaskQuards Failed: Wants %v Got %v", wants[1], got[1])
}
if got[2] != wants[2] {
t.Errorf("Third Value of GetSubnetMaskQuards Failed: Wants %v Got %v", wants[2], got[2])
}
if got[3] != wants[3] {
t.Errorf("Fourth Value of GetSubnetMaskQuards Failed: Wants %v Got %v", wants[3], got[3])
}
}
func TestGetSubnetMaskHex(t *testing.T) {
wants := builder().subnetMaskHex
got := ip().GetSubnetMaskHex()
if wants != got {
t.Errorf("GetSubnetMaskHex Failed: Wants %v Got %v", wants, got)
}
}
func TestGetSubnetMaskBinary(t *testing.T) {
wants := builder().subnetMaskBinary
got := ip().GetSubnetMaskBinary()
if wants != got {
t.Errorf("GetSubnetMaskBinary Failed: Wants %v Got %v", wants, got)
}
}
func TestGetNetworkPortion(t *testing.T) {
wants := builder().networkPortion
got := ip().GetNetworkPortion()
if wants != got {
t.Errorf("GetNetworkPortion Failed: Wants %v Got %v", wants, got)
}
}
func TestGetNetworkPortionQuards(t *testing.T) {
wants := builder().networkPortionQuards
got := ip().GetNetworkPortionQuards()
if got[0] != wants[0] {
t.Errorf("First Value of GetNetworkPortionQuards Failed: Wants %v Got %v", wants[0], got[0])
}
if got[1] != wants[1] {
t.Errorf("Second Value of GetNetworkPortionQuards Failed: Wants %v Got %v", wants[1], got[1])
}
if got[2] != wants[2] {
t.Errorf("Third Value of GetNetworkPortionQuards Failed: Wants %v Got %v", wants[2], got[2])
}
if got[3] != wants[3] {
t.Errorf("Fourth Value of GetNetworkPortionQuards Failed: Wants %v Got %v", wants[3], got[3])
}
}
func TestGetNetworkPortionHex(t *testing.T) {
wants := builder().networkPortionHex
got := ip().GetNetworkPortionHex()
if wants != got {
t.Errorf("GetNetworkPortionHex Failed: Wants %v Got %v", wants, got)
}
}
func TestGetNetworkPortionBinary(t *testing.T) {
wants := builder().networkPortionBinary
got := ip().GetNetworkPortionBinary()
if wants != got {
t.Errorf("GetSubnetMaskBinary Failed: Wants %v Got %v", wants, got)
}
}
func TestGetHostPortion(t *testing.T) {
wants := builder().hostPortion
got := ip().GetHostPortion()
if wants != got {
t.Errorf("GetHostPortion Failed: Wants %v Got %v", wants, got)
}
}
func TestGetHostPortionQuards(t *testing.T) {
wants := builder().hostPortionQuards
got := ip().GetHostPortionQuards()
if got[0] != wants[0] {
t.Errorf("First Value of GetHostPortionQuards Failed: Wants %v Got %v", wants[0], got[0])
}
if got[1] != wants[1] {
t.Errorf("Second Value of GetHostPortionQuards Failed: Wants %v Got %v", wants[1], got[1])
}
if got[2] != wants[2] {
t.Errorf("Third Value of GetHostPortionQuards Failed: Wants %v Got %v", wants[2], got[2])
}
if got[3] != wants[3] {
t.Errorf("Fourth Value of GetHostPortionQuards Failed: Wants %v Got %v", wants[3], got[3])
}
}
func TestGetHostPortionHex(t *testing.T) {
wants := builder().hostPortionHex
got := ip().GetHostPortionHex()
if wants != got {
t.Errorf("GetHostPortionHex Failed: Wants %v Got %v", wants, got)
}
}
func TestGetHostPortionBinary(t *testing.T) {
wants := builder().hostPortionBinary
got := ip().GetHostPortionBinary()
if wants != got {
t.Errorf("GetSubnetMaskBinary Failed: Wants %v Got %v", wants, got)
}
}