Skip to content

Commit 477b683

Browse files
committed
✅ 🔥 Add tests; remove old SQL script
1 parent f2d3f6a commit 477b683

4 files changed

+89
-180
lines changed

Find-SqlDeprecatedLargeValueTypes.ps1

-180
This file was deleted.

Format-ByteUnits.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ http://physics.nist.gov/cuu/Units/binary.html
1919
2020
.EXAMPLE
2121
Format-ByteUnits 65536
22+
2223
64KB
2324
2425
.EXAMPLE
2526
Format-ByteUnits 9685059 -dot 1 -si
27+
2628
9.2 MiB
2729
2830
.EXAMPLE
2931
ls *.log |measure -sum Length |select -exp Sum |Format-ByteUnits -dot 2 -si
32+
3033
302.39 MiB
3134
#>
3235

test/ForEach-Progress.Tests.ps1

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<#
2+
.SYNOPSIS
3+
Tests performing an operation against each item in a collection of input objects, with a progress bar.
4+
#>
5+
6+
$basename = "$(($MyInvocation.MyCommand.Name -split '\.',2)[0])."
7+
$skip = !(Test-Path .changes -Type Leaf) ? $false :
8+
!@(Get-Content .changes |Get-Item |Select-Object -ExpandProperty Name |Where-Object {$_.StartsWith($basename)})
9+
if($skip) {Write-Information "No changes to $basename" -infa Continue}
10+
Describe 'ForEach-Progress' -Tag ForEach-Progress -Skip:$skip {
11+
BeforeAll {
12+
$scriptsdir,$sep = (Split-Path $PSScriptRoot),[io.path]::PathSeparator
13+
if($scriptsdir -notin ($env:Path -split $sep)) {$env:Path += "$sep$scriptsdir"}
14+
}
15+
Context 'Performs an operation against each item in a collection of input objects, with a progress bar' `
16+
-Tag ForEachProgress,ForEach,Progress {
17+
It "Displays progress" {
18+
Mock Write-Progress {}
19+
1..10 |ForEach-Progress.ps1 -Activity 'Processing' {"$_"} {"$_"}
20+
Assert-MockCalled -CommandName Write-Progress -Times 10
21+
}
22+
}
23+
}

test/Format-ByteUnits.Tests.ps1

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<#
2+
.SYNOPSIS
3+
Tests converting bytes to largest possible units, to improve readability.
4+
#>
5+
6+
$basename = "$(($MyInvocation.MyCommand.Name -split '\.',2)[0])."
7+
$skip = !(Test-Path .changes -Type Leaf) ? $false :
8+
!@(Get-Content .changes |Get-Item |Select-Object -ExpandProperty Name |Where-Object {$_.StartsWith($basename)})
9+
if($skip) {Write-Information "No changes to $basename" -infa Continue}
10+
Describe 'Format-ByteUnits' -Tag Format-ByteUnits -Skip:$skip {
11+
BeforeAll {
12+
$scriptsdir,$sep = (Split-Path $PSScriptRoot),[io.path]::PathSeparator
13+
if($scriptsdir -notin ($env:Path -split $sep)) {$env:Path += "$sep$scriptsdir"}
14+
}
15+
Context 'Converts bytes to largest possible units, to improve readability' -Tag FormatByteUnits,Format,ByteUnits {
16+
It "Formatting '<Bytes>', up to '<Precision>' digits after the decimal returns '<Result>', or '<SIResult> for SI'" -TestCases @(
17+
@{ Bytes = 0; Precision = 16; Result = '0'; SIResult = '0' }
18+
@{ Bytes = 1; Precision = 16; Result = '1'; SIResult = '1 B' }
19+
@{ Bytes = 999; Precision = 16; Result = '999'; SIResult = '999 B' }
20+
@{ Bytes = 0KB; Precision = 16; Result = '0'; SIResult = '0' }
21+
@{ Bytes = 1KB; Precision = 16; Result = '1KB'; SIResult = '1 KiB' }
22+
@{ Bytes = 999KB; Precision = 16; Result = '999KB'; SIResult = '999 KiB' }
23+
@{ Bytes = 1MB; Precision = 16; Result = '1MB'; SIResult = '1 MiB' }
24+
@{ Bytes = 999MB; Precision = 16; Result = '999MB'; SIResult = '999 MiB' }
25+
@{ Bytes = 1GB; Precision = 16; Result = '1GB'; SIResult = '1 GiB' }
26+
@{ Bytes = 999GB; Precision = 16; Result = '999GB'; SIResult = '999 GiB' }
27+
@{ Bytes = 1TB; Precision = 16; Result = '1TB'; SIResult = '1 TiB' }
28+
@{ Bytes = 999TB; Precision = 16; Result = '999TB'; SIResult = '999 TiB' }
29+
@{ Bytes = 1PB; Precision = 16; Result = '1PB'; SIResult = '1 PiB' }
30+
@{ Bytes = 999PB; Precision = 16; Result = '999PB'; SIResult = '999 PiB' }
31+
@{ Bytes = 999999999999999999N; Precision = 2; Result = '888.18PB'; SIResult = '888.18 PiB' }
32+
@{ Bytes = 1234567890L; Precision = 2; Result = '1.15GB'; SIResult = '1.15 GiB' }
33+
@{ Bytes = 1234567890L; Precision = 1; Result = '1.1GB'; SIResult = '1.1 GiB' }
34+
@{ Bytes = 1234567890L; Precision = 0; Result = '1GB'; SIResult = '1 GiB' }
35+
@{ Bytes = 987654321000; Precision = 16; Result = '919.824765063822GB'; SIResult = '919.824765063822 GiB' }
36+
@{ Bytes = 987654321000; Precision = 12; Result = '919.824765063822GB'; SIResult = '919.824765063822 GiB' }
37+
@{ Bytes = 987654321000; Precision = 11; Result = '919.82476506382GB'; SIResult = '919.82476506382 GiB' }
38+
@{ Bytes = 987654321000; Precision = 10; Result = '919.8247650638GB'; SIResult = '919.8247650638 GiB' }
39+
@{ Bytes = 987654321000; Precision = 9; Result = '919.824765064GB'; SIResult = '919.824765064 GiB' }
40+
@{ Bytes = 987654321000; Precision = 8; Result = '919.82476506GB'; SIResult = '919.82476506 GiB' }
41+
@{ Bytes = 987654321000; Precision = 7; Result = '919.8247651GB'; SIResult = '919.8247651 GiB' }
42+
@{ Bytes = 987654321000; Precision = 6; Result = '919.824765GB'; SIResult = '919.824765 GiB' }
43+
@{ Bytes = 987654321000; Precision = 5; Result = '919.82477GB'; SIResult = '919.82477 GiB' }
44+
@{ Bytes = 987654321000; Precision = 4; Result = '919.8248GB'; SIResult = '919.8248 GiB' }
45+
@{ Bytes = 987654321000; Precision = 3; Result = '919.825GB'; SIResult = '919.825 GiB' }
46+
@{ Bytes = 987654321000; Precision = 2; Result = '919.82GB'; SIResult = '919.82 GiB' }
47+
@{ Bytes = 987654321000; Precision = 1; Result = '919.8GB'; SIResult = '919.8 GiB' }
48+
@{ Bytes = 987654321000; Precision = 0; Result = '920GB'; SIResult = '920 GiB' }
49+
@{ Bytes = 9685059; Precision = 1; Result = '9.2MB'; SIResult = '9.2 MiB' }
50+
) {
51+
Param([bigint] $Bytes, [byte] $Precision, [string] $Result, [string] $SIResult)
52+
Format-ByteUnits.ps1 -Bytes $Bytes -Precision $Precision |
53+
Should -BeExactly $Result -Because 'parameter should work'
54+
$Bytes |Format-ByteUnits.ps1 -Precision $Precision |
55+
Should -BeExactly $Result -Because 'pipeline should work'
56+
Format-ByteUnits.ps1 -Bytes $Bytes -Precision $Precision -UseSI |
57+
Should -BeExactly $SIResult -Because 'SI parameter should work'
58+
$Bytes |Format-ByteUnits.ps1 -Precision $Precision -UseSI |
59+
Should -BeExactly $SIResult -Because 'SI pipeline should work'
60+
}
61+
}
62+
63+
}

0 commit comments

Comments
 (0)