diff --git a/functional.psm1 b/functional.psm1 index 5af1283..cf6a1dc 100644 --- a/functional.psm1 +++ b/functional.psm1 @@ -59,13 +59,22 @@ function recursiveEquality($a, $b) { $inequalIndexes = 0..($a.Count - 1) | ? { -not (recursiveEquality $a[$_] $b[$_]) } return $inequalIndexes.Count -eq 0 } - if ($a -is [hashtable] -and $b -is [hashtable]) { + if ($a -is [hashtable] -and $b -is [hashtable]){ Write-Debug "recursively test hashtable '$a' '$b'" $inequalKeys = $a.Keys + $b.Keys ` | Sort-Object -Unique ` | ? { -not (recursiveEquality $a[$_] $b[$_]) } return $inequalKeys.Count -eq 0 } + + if ($a -is [System.Collections.IDictionary] -and $b -is [System.Collections.IDictionary]){ + Write-Debug "recursively test Ordered Dictionary'$a' '$b'" + $inequalKeys = $a.Keys + $b.Keys ` + | Sort-Object -Unique ` + | ? { -not (recursiveEquality $a[$_] $b[$_]) } + return $inequalKeys.Count -eq 0 + } + if ((isPsCustomObject $a) -and (isPsCustomObject $b)) { Write-Debug "a is pscustomobject: $($a -is [psobject])" Write-Debug "recursively test objects '$a' '$b'" diff --git a/functional.tests.ps1 b/functional.tests.ps1 index c0392ac..bbb5244 100644 --- a/functional.tests.ps1 +++ b/functional.tests.ps1 @@ -278,14 +278,21 @@ Describe "Test-Equality" { @{a = 1; b = @{c = 2 } }, @{a = 1; b = @{c = 2 } } | Test-Equality | Should -BeTrue } } - Context "Given an array of PSCustomObject" { - $a = @([PSCustomObject]@{ 'Name' = 'Foo'; 'Value' = 'Foo' }, [PSCustomObject]@{ 'Name' = 'Baz'; 'Value' = 'Baz' } ) - $b = @([PSCustomObject]@{ 'Name' = 'xxx'; 'Value' = 'Foo' }, [PSCustomObject]@{ 'Name' = 'Baz'; 'Value' = 'Baz' } ) + Context "Given Ordered Dictionaries" { It "Should be false for deep inequal values" { - $a, $b | Test-Equality | Should -BeFalse + [ordered]@{a = 1; b = @{c = 2 } }, [ordered]@{a = 1; b = [pscustomobject]@{c = 2 } } | Test-Equality | Should -BeFalse } It "Should be true for deep equal values" { - $a, $a | Test-Equality | Should -BeTrue + [ordered]@{a = 1; b = @{c = 2 } }, [ordered]@{a = 1; b = @{c = 2 } } | Test-Equality | Should -BeTrue + } + } + Context "Given an array of PSCustomObject" { + BeforeAll{ + $a = @([PSCustomObject]@{ 'Name' = 'Foo'; 'Value' = 'Foo' }, [PSCustomObject]@{ 'Name' = 'Baz'; 'Value' = 'Baz' } ) + $b = @([PSCustomObject]@{ 'Name' = 'xxx'; 'Value' = 'Foo' }, [PSCustomObject]@{ 'Name' = 'Baz'; 'Value' = 'Baz' } ) + } + It "Should be false for deep inequal values" { + $a, $b | Test-Equality | Should -BeFalse } } }