I was struggling with this Kata "Sum Of Positive".
On my computer:
Sum-OfPositive($test = @(1, 2, 3, 4, 5))
15
The function should work as intended, but I can't pass the tests.
What's wrong?
I am using Powershell 6.0.
On 7.2 will not pass for reasons which are unknown to me. Can someone also explain me why?
function Get-SumOfPositive($NumberArray)
{
$Sum =0;
foreach($Number in $NumbArray){
if($Number -gt 0){
$Sum+=$Number
}
}
Write-Output $Sum
}
Describe "Fixed Tests"{
it "Should pass"{
$test = @(1, 2, 3, 4, 5)
Get-SumOfPositive($test) | Should be 15
}
it "Should pass"{
$test = @(1, -2, 3, 4, 5)
Get-SumOfPositive($test) | Should be 13
}
it "Should pass"{
$test = @(-1, 2, 3, 4, -5)
Get-SumOfPositive($test) | Should be 9
}
it "Should pass"{
$test = @()
Get-SumOfPositive($test) | Should be 0
}
it "Should pass"{
$test = (-1, -2, -3, -4, -5)
Get-SumOfPositive($test) | Should be 0
}
}