Permalink
Browse files

Created Pester Test and fixed code bugs

  • Loading branch information...
Houben
Houben committed May 30, 2018
1 parent 5870cc9 commit b80b2bcd8a6144430a4b65495adf0e47760195f6
@@ -1,4 +1,34 @@
Input;ExpectedIpCidr;ExpectedIpAddress;ExpectedSubnetMask;ExpectedIpAndSubnetMask
192.168.1.1/0;192.168.1.1/0;192.168.1.1;0.0.0.0;192.168.1.1 0.0.0.0
192.168.1.1/1;192.168.1.1/1;192.168.1.1;128.0.0.0;192.168.1.1 128.0.0.0
192.168.1.1/2;192.168.1.1/2;192.168.1.1;192.0.0.0;192.168.1.1 192.0.0.0
192.168.1.1/2;192.168.1.1/2;192.168.1.1;192.0.0.0;192.168.1.1 192.0.0.0
192.168.1.1/3;192.168.1.1/3;192.168.1.1;224.0.0.0;192.168.1.1 224.0.0.0
192.168.1.1/4;192.168.1.1/4;192.168.1.1;240.0.0.0;192.168.1.1 240.0.0.0
192.168.1.1/5;192.168.1.1/5;192.168.1.1;248.0.0.0;192.168.1.1 248.0.0.0
192.168.1.1/6;192.168.1.1/6;192.168.1.1;252.0.0.0;192.168.1.1 252.0.0.0
192.168.1.1/7;192.168.1.1/7;192.168.1.1;254.0.0.0;192.168.1.1 254.0.0.0
192.168.1.1/8;192.168.1.1/8;192.168.1.1;255.0.0.0;192.168.1.1 255.0.0.0
192.168.1.1/9;192.168.1.1/9;192.168.1.1;255.128.0.0;192.168.1.1 255.128.0.0
192.168.1.1/10;192.168.1.1/10;192.168.1.1;255.192.0.0;192.168.1.1 255.192.0.0
192.168.1.1/11;192.168.1.1/11;192.168.1.1;255.224.0.0;192.168.1.1 255.224.0.0
192.168.1.1/12;192.168.1.1/12;192.168.1.1;255.240.0.0;192.168.1.1 255.240.0.0
192.168.1.1/13;192.168.1.1/13;192.168.1.1;255.248.0.0;192.168.1.1 255.248.0.0
192.168.1.1/14;192.168.1.1/14;192.168.1.1;255.252.0.0;192.168.1.1 255.252.0.0
192.168.1.1/15;192.168.1.1/15;192.168.1.1;255.254.0.0;192.168.1.1 255.254.0.0
192.168.1.1/16;192.168.1.1/16;192.168.1.1;255.255.0.0;192.168.1.1 255.255.0.0
192.168.1.1/17;192.168.1.1/17;192.168.1.1;255.255.128.0;192.168.1.1 255.255.128.0
192.168.1.1/18;192.168.1.1/18;192.168.1.1;255.255.192.0;192.168.1.1 255.255.192.0
192.168.1.1/19;192.168.1.1/19;192.168.1.1;255.255.224.0;192.168.1.1 255.255.224.0
192.168.1.1/20;192.168.1.1/20;192.168.1.1;255.255.240.0;192.168.1.1 255.255.240.0
192.168.1.1/21;192.168.1.1/21;192.168.1.1;255.255.248.0;192.168.1.1 255.255.248.0
192.168.1.1/22;192.168.1.1/22;192.168.1.1;255.255.252.0;192.168.1.1 255.255.252.0
192.168.1.1/23;192.168.1.1/23;192.168.1.1;255.255.254.0;192.168.1.1 255.255.254.0
192.168.1.1/24;192.168.1.1/24;192.168.1.1;255.255.255.0;192.168.1.1 255.255.255.0
192.168.1.1/25;192.168.1.1/25;192.168.1.1;255.255.255.128;192.168.1.1 255.255.255.128
192.168.1.1/26;192.168.1.1/26;192.168.1.1;255.255.255.192;192.168.1.1 255.255.255.192
192.168.1.1/27;192.168.1.1/27;192.168.1.1;255.255.255.224;192.168.1.1 255.255.255.224
192.168.1.1/28;192.168.1.1/28;192.168.1.1;255.255.255.240;192.168.1.1 255.255.255.240
192.168.1.1/29;192.168.1.1/29;192.168.1.1;255.255.255.248;192.168.1.1 255.255.255.248
192.168.1.1/30;192.168.1.1/30;192.168.1.1;255.255.255.252;192.168.1.1 255.255.255.252
192.168.1.1/31;192.168.1.1/31;192.168.1.1;255.255.255.254;192.168.1.1 255.255.255.254
192.168.1.1/32;192.168.1.1/32;192.168.1.1;255.255.255.255;192.168.1.1 255.255.255.255
@@ -2,18 +2,23 @@
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe "Convert-IPCIDRNotationtoIPSubnetMaskNotation" {
$Result = Convert-IPCIDRNotationtoIPSubnetMaskNotation -IPCIDR '192.168.1.2/24'
It "IPCIDR result should be 192.168.1.2/24" {
$Result | Select-Object -ExpandProperty IPCIDR | Should -Be '192.168.1.2/24'
}
It "IPAddress result should be 192.168.1.2" {
$Result | Select-Object -ExpandProperty IpAddress | Should -Be '192.168.1.2'
}
It "SubNetMask result should be 255.255.255.0" {
$Result | Select-Object -ExpandProperty SubNetMask | Should -Be '255.255.255.0'
}
It "Ip and subnet mask result should be 192.168.1.2 255.255.255.0" {
$Result | Select-Object -ExpandProperty IpAndSubNetMask | Should -Be '192.168.1.2 255.255.255.0'
$Tests = Import-Csv -path "$here\Convert-IPCidrNotationToIpSubnetMaskNotation.Tests.Csv" -Delimiter ';'
Foreach ($Test in $Tests)
{
Describe "Convert-IPCIDRNotationtoIPSubnetMaskNotation for $($Test.Input)" {
$Result = Convert-IPCIDRNotationtoIPSubnetMaskNotation -IPCIDR $Test.Input
It "IPCIDR result should be $($Test.ExpectedIpCIDR)" {
$Result | Select-Object -ExpandProperty IPCIDR | Should -Be $($Test.ExpectedIpCIDR)
}
It "IPAddress result should be $($Test.ExpectedIPAddress)" {
$Result | Select-Object -ExpandProperty IpAddress | Should -Be $($Test.ExpectedIPAddress)
}
It "SubNetMask result should be $($Test.ExpectedSubnetMask)" {
$Result | Select-Object -ExpandProperty SubNetMask | Should -Be $($Test.ExpectedSubnetMask)
}
It "Ip and subnet mask result should be $($Test.ExpectedIpAndSubnetMask)" {
$Result | Select-Object -ExpandProperty IpAndSubNetMask | Should -Be $($Test.ExpectedIpAndSubnetMask)
}
}
}
}
@@ -149,7 +149,7 @@
$SubnetMask = switch ($CIDR) #Get the subnet mask belonging to the CIDR notation
{
default {'Error'}
0 {'0.0.0.0.'}
0 {'0.0.0.0'}
1 {'128.0.0.0'}
2 {'192.0.0.0'}
3 {'224.0.0.0'}
@@ -179,8 +179,8 @@
27 {'255.255.255.224'}
28 {'255.255.255.240'}
29 {'255.255.255.248'}
31 {'255.255.255.252'}
30 {'255.255.255.254'}
30 {'255.255.255.252'}
31 {'255.255.255.254'}
32 {'255.255.255.255'}
}

0 comments on commit b80b2bc

Please sign in to comment.