Skip to content

Instantly share code, notes, and snippets.

View chriskuech's full-sized avatar

Chris Kuech chriskuech

  • Datum Source, ex MSFT
View GitHub Profile
recursiveEquality $test $expected | Should -BeTrue
# modified from https://github.com/chriskuech/functional
function recursiveEquality($a, $b) {
# recursive step for arrays
if ($a -is [array] -and $b -is [array]) {
if ($a.Count -ne $b.Count) {
return $false
}
$inequalIndexes = 0..($a.Count - 1) | ? { -not (recursiveEquality $a[$_] $b[$_]) }
return $inequalIndexes.Count -eq 0
}
$myObj = @{}
$myObj["a"] = $myObj
@{ # depth 1
a = @( # depth 2
1,
@{ # depth 3
b = 2
}
)
}
function Assert-ArrayEquality($test, $expected) {
$test | Should -HaveCount $expected.Count
0..($test.Count - 1) | % {$test[$_] | Should -Be $expected[$_]}
}
function Assert-HashtableEquality($test, $expected) {
$test.Keys | Should -HaveCount $expected.Keys.Count
$test.Keys | % {$test[$_] | Should -Be $expected[$_]}
}
$test | Should -HaveCount $expected.Count
$test[3] | Should -Be $expected[3]
PS> $a, $b = @{}, @{}
PS> $a -eq $a
True
PS> $a -eq $b
False
PS> @{} | Should -Be @{}
Expected System.Collections.Hashtable, but got System.Collections.Hashtable.
PS> @{} -eq @{}
False
PS> [PSCustomObject]@{} -eq [PSCustomObject]@{}
False
PS> @() -eq @() # doesn't even output True or False
PS> @(1, 2, 3) -eq @(1, 2, 3) # doesn't even output True or False
PS> 4 -eq 4
True
PS> "joe estevez" -eq "emilio estevez"
False
PS> "Joe Estevez" -eq "joe estevez"
True