I decided to golf up this kumite - for the sanity of the tester, I trim the function definition to remove leading or trailing spaces.
Write-Verbose (Get-Module pester -listAvailable).Version.ToString() function calculate_multiples { (1..999|?{!($_%3) -or !($_%5)}|measure -s).sum }
- Write-Verbose (Get-Module pester -listAvailable).Version.ToString()
- function calculate_multiples {
$SUM = 01..999 | ForEach-Object {if (!( $_ % 3) -OR !($_ % 5)) {$Sum += $_}}return $Sum- (1..999|?{!($_%3) -or !($_%5)}|measure -s).sum
- }
# You can test with Pester (https://github.com/pester/Pester) # TODO: replace with your own tests (TDD), these are just here to demonstrate usage. $Results = calculate_multiples Describe 'My Solution' { It 'Should return 233168' { $Results | Should be 233168 } It 'Should be short' { (get-item Function:\calculate_multiples).Definition.Trim().Length -lt 50 #$true } }
- # You can test with Pester (https://github.com/pester/Pester)
- # TODO: replace with your own tests (TDD), these are just here to demonstrate usage.
- $Results = calculate_multiples
- Describe 'My Solution' {
- It 'Should return 233168' {
- $Results | Should be 233168
- }
- It 'Should be short' {
- (get-item Function:\calculate_multiples).Definition.Trim().Length -lt 50
- #$true
- }
- }