Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
OrderedHashtable.Tests.ps1163 linesDownload Raw Back to engine
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Describe 'Tests for OrderedHashtable' -Tag 'CI' {5 6    It 'Can create an empty OrderedHashtable' {7        $oh =[System.Management.Automation.OrderedHashtable]::new()8        $oh.Count | Should -Be 09        $oh.GetType().Name | Should -BeExactly 'OrderedHashtable'10    }11 12    It 'Can create an empty OrderedHashtable with a capacity' {13        $oh = [System.Management.Automation.OrderedHashtable]::new(10)14        $oh.Count | Should -Be 015        $oh.GetType().Name | Should -BeExactly 'OrderedHashtable'16    }17 18    It 'Can create an OrderedHashtable with an initial dictionary' {19        $h = @{ a = 1; b = 2 }20        $oh = [System.Management.Automation.OrderedHashtable]::new($h)21        $oh.Count | Should -Be 222        $oh['a'] | Should -Be $h['a']23        $oh['b'] | Should -Be $h['b']24    }25 26    It 'Can use the Add() method' {27        $oh = [System.Management.Automation.OrderedHashtable]::new()28        $oh.Add('a', 1)29        $oh.Add('b', 2)30        $oh.Count | Should -Be 231        $oh['a'] | Should -Be 132        $oh['b'] | Should -Be 233    }34 35    It 'Can use the Clear() method' {36        $h = @{ a = 1; b = 2 }37        $oh = [System.Management.Automation.OrderedHashtable]::new($h)38        $oh.Count | Should -Be 239        $oh.Clear()40        $oh.Count | Should -Be 041    }42 43    It 'Can use the Clone() method' {44        $h = @{ a = 1; b = 2 }45        $oh = [System.Management.Automation.OrderedHashtable]::new($h)46        $oh2 = $oh.Clone()47        $oh2.Count | Should -Be 248        $oh2['a'] | Should -Be $h['a']49        $oh2['b'] | Should -Be $h['b']50    }51 52    It 'Can use the Contains() method' {53        $h = @{ a = 1; b = 2 }54        $oh = [System.Management.Automation.OrderedHashtable]::new($h)55        $oh.Contains('a') | Should -BeTrue56        $oh.Contains('b') | Should -BeTrue57        $oh.Contains('c') | Should -BeFalse58    }59 60    It 'Can use the ContainsKey() method' {61        $h = @{ a = 1; b = 2 }62        $oh = [System.Management.Automation.OrderedHashtable]::new($h)63        $oh.ContainsKey('a') | Should -BeTrue64        $oh.ContainsKey('b') | Should -BeTrue65        $oh.ContainsKey('c') | Should -BeFalse66    }67 68    It 'Can use the ContainsValue() method' {69        $h = @{ a = 1; b = 2 }70        $oh = [System.Management.Automation.OrderedHashtable]::new($h)71        $oh.ContainsValue(1) | Should -BeTrue72        $oh.ContainsValue(2) | Should -BeTrue73        $oh.ContainsValue(3) | Should -BeFalse74    }75 76    It 'Can use the CopyTo() method' {77        $oh = [System.Management.Automation.OrderedHashtable]::new()78        $oh.Add('a', 1)79        $oh.Add('b', 2)80        $oh.Add('c', 3)81        $a = (4, 5, 6, 7)82        $oh.CopyTo($a, 1)83        $a[0] | Should -Be 484        # OrderedDictionary.CopyTo() doesn't guarantee to preserve order85        # so we can't easily test the values86        $a[1].GetType().Name | Should -BeExactly 'DictionaryEntry'87        $a[2].GetType().Name | Should -BeExactly 'DictionaryEntry'88        $a[3].GetType().Name | Should -BeExactly 'DictionaryEntry'89    }90 91    It 'Can use the Equals() method' {92        $h = @{ a = 1; b = 2 }93        $oh = [System.Management.Automation.OrderedHashtable]::new($h)94        $oh2 = $oh.Clone()95        $oh3 = $oh96        $oh.Equals($oh2) | Should -BeFalse97        $oh.Equals($oh3) | Should -BeTrue98    }99 100    It 'Can use the GetEnumerator() method' {101        $h = @{ a = 1; b = 2 }102        $oh = [System.Management.Automation.OrderedHashtable]::new($h)103        $oh.GetEnumerator().GetType().Name | Should -BeExactly 'OrderedDictionaryEnumerator'104    }105 106    It 'Can use the GetHashCode() method' {107        $h = @{ a = 1; b = 2 }108        $oh = [System.Management.Automation.OrderedHashtable]::new($h)109        $oh.GetHashCode() | Should -BeGreaterThan 0110        $oh2 = $oh.Clone()111        $oh.GetHashCode() | Should -Not -Be $oh2.GetHashCode()112        $oh3 = $oh113        $oh.GetHashCode() | Should -Be $oh3.GetHashCode()114    }115 116    It 'Can use Remove() method' {117        $h = @{ a = 1; b = 2 }118        $oh = [System.Management.Automation.OrderedHashtable]::new($h)119        $oh.Remove('a')120        $oh.Count | Should -Be 1121        $oh.Contains('a') | Should -BeFalse122    }123 124    It 'Can use Item property' {125        $h = @{ a = 1; b = 2 }126        $oh = [System.Management.Automation.OrderedHashtable]::new($h)127        $oh['a'] | Should -Be 1128        $oh['b'] | Should -Be 2129    }130 131    It 'Can use IsFixedSize property' {132        $h = @{ a = 1; b = 2 }133        $oh = [System.Management.Automation.OrderedHashtable]::new($h)134        $oh.IsFixedSize | Should -BeFalse135    }136 137    It 'Can use IsReadOnly property' {138        $h = @{ a = 1; b = 2 }139        $oh = [System.Management.Automation.OrderedHashtable]::new($h)140        $oh.IsReadOnly | Should -BeFalse141    }142 143    It 'Can use IsSynchronized property' {144        $h = @{ a = 1; b = 2 }145        $oh = [System.Management.Automation.OrderedHashtable]::new($h)146        $oh.IsSynchronized | Should -BeFalse147    }148 149    It 'Can use Keys property' {150        $oh = [System.Management.Automation.OrderedHashtable]::new()151        $oh['a'] = 1152        $oh['b'] = 2153        $oh.Keys | Should -Be ('a', 'b')154    }155 156    It 'Can use Values property' {157        $oh = [System.Management.Automation.OrderedHashtable]::new()158        $oh['a'] = 1159        $oh['b'] = 2160        $oh.Values | Should -Be (1, 2)161    }162}163