From 5d91a8164fb4483819422a53e263f9bcb4fe3f68 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 21 Apr 2016 21:54:09 -0700 Subject: [PATCH 1/4] Add Unit Test for Get-Random --- test/powershell/Get-Random.Tests.ps1 | 249 +++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) diff --git a/test/powershell/Get-Random.Tests.ps1 b/test/powershell/Get-Random.Tests.ps1 index 0d769846e..f62cbebef 100644 --- a/test/powershell/Get-Random.Tests.ps1 +++ b/test/powershell/Get-Random.Tests.ps1 @@ -1,3 +1,252 @@ +Describe "Get-Random DRT Unit Tests" -Tags DRT{ + + # -minimum is always set to the actual low end of the range, details refer to closed issue #887 + It "Tests for random-numbers mode" { + # Test for Int32 + $results = get-random + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan ([int32]::MaxValue) + + $results = get-random 100 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan 100 + + $x = 10000 + $results = get-random $x + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan 10000 + + $results = get-random -Minimum -100 -Maximum 0 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -101 + $results | Should BeLessThan 0 + + $results = get-random -Minimum -100 -Maximum 100 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -101 + $results | Should BeLessThan 100 + + $results = get-random -Minimum -200 -Maximum -100 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -201 + $results | Should BeLessThan -100 + + $results = get-random -Minimum (-200) -Maximum (-100) + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -201 + $results | Should BeLessThan -100 + + $results = get-random -Minimum 5 -Maximum '8' + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan 4 + $results | Should BeLessThan 8 + + $results = get-random -Minimum '5' -Maximum 8 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan 4 + $results | Should BeLessThan 8 + + $results = get-random -Minimum 0 -Maximum +100 + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan 100 + + $results = get-random -Minimum 0 -Maximum '+100' + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan 100 + + $results = get-random -Minimum '-100' -Maximum '+100' + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -101 + $results | Should BeLessThan 100 + + $results = get-random -Minimum 0 -Maximum '1kb' + $results.GetType().FullName | Should Be System.Int32 + $results | Should BeGreaterThan -1 + $results | Should BeLessThan 1024 + + #Test for Int64 + $results = get-random ([int64]::MaxValue) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-1) + $results | Should BeLessThan ([int64]::MaxValue) + + $results = get-random ([int64]100) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-1) + $results | Should BeLessThan ([int64]100) + + $results = get-random 100000000000 + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-1) + $results | Should BeLessThan ([int64]100000000000) + + $results = get-random -Minimum ([int64]-100) -Maximum ([int64]0) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-101) + $results | Should BeLessThan ([int64]0) + + $results = get-random -Minimum ([int64]-100) -Maximum ([int64]100) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-101) + $results | Should BeLessThan ([int64]100) + + $results = get-random -Minimum ([int64]-200) -Maximum ([int64]-100) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-201) + $results | Should BeLessThan ([int64]-100) + + $results = get-random -Minimum ([int64](-200)) -Maximum ([int64](-100)) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-201) + $results | Should BeLessThan ([int64]-100) + + + $results = get-random -Minimum ([int64]5) -Maximum '8' + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]4) + $results | Should BeLessThan ([int64]8) + + $results = get-random -Minimum '5' -Maximum ([int64]8) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]4) + $results | Should BeLessThan ([int64]8) + + $results = get-random -Minimum ([int64]0) -Maximum +100 + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-1) + $results | Should BeLessThan ([int64]100) + + $results = get-random -Minimum ([int64]0) -Maximum '+100' + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-1) + $results | Should BeLessThan ([int64]100) + + $results = get-random -Minimum '-100' -Maximum ([int64]0) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]-101) + $results | Should BeLessThan ([int64]0) + + $results = get-random -Minimum '1mb' -Maximum ([int64]1048585) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]1048575) + $results | Should BeLessThan ([int64]1048585) + + $results = get-random -Minimum '10mb' -Maximum '1tb' + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]10485759) + $results | Should BeLessThan ([int64]1099511627776) + + $results = get-random -Minimum ([int64]::MinValue) -Maximum ([int64]::MaxValue) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]::MinValue) + $results | Should BeLessThan ([int64]::MaxValue) + + $results = get-random -Minimum ([int64](([int]::MaxValue)+10)) -Maximum ([int64](([int]::MaxValue)+15)) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]([int32]::MaxValue + 9)) + $results | Should BeLessThan ([int64]([int32]::MaxValue + 15)) + + $results = get-random -Minimum ([int64](([int]::MaxValue)+100)) -Maximum ([int64](([int]::MaxValue)+150)) + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]([int32]::MaxValue + 99)) + $results | Should BeLessThan ([int64]([int32]::MaxValue + 150)) + + $results = get-random -Minimum 100000000001 -Maximum '100099000001' + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]100000000000) + $results | Should BeLessThan ([int64]100099000001) + + $results = get-random -Minimum '100000002222' -Maximum 100000002230 + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]100000002221) + $results | Should BeLessThan ([int64]100000002230) + + $results = get-random -Minimum 4 -Maximum 90000000000 + $results.GetType().FullName | Should Be System.Int64 + $results | Should BeGreaterThan ([int64]3) + $results | Should BeLessThan ([int64]90000000000) + + #Test for double + $results = get-random 100.0 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -1.0 + $results | Should BeLessThan 100.0 + + $results = get-random -Minimum -100.0 -Maximum 0.0 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -101.0 + $results | Should BeLessThan 0.0 + + $results = get-random -Minimum -100.0 -Maximum 100.0 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -101.0 + $results | Should BeLessThan 100.0 + + $results = get-random -Minimum 5 -Maximum 8.0 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan 4.0 + $results | Should BeLessThan 8.0 + + $results = get-random -Minimum 5.0 -Maximum 8 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan 4.0 + $results | Should BeLessThan 8.0 + + $results = get-random -Minimum 0.0 -Maximum 20. + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -1.0 + $results | Should BeLessThan 20.0 + + $results = get-random -Minimum 0.0 -Maximum '20.' + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -1.0 + $results | Should BeLessThan 20.0 + + $results = get-random -Minimum 0 -Maximum +100.0 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -1.0 + $results | Should BeLessThan 100.0 + + $results = get-random -Minimum 0 -Maximum '+100.0' + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan -1.0 + $results | Should BeLessThan 100.0 + + $results = get-random -Minimum 1.0e+100 + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan 1.0e+99 + $results | Should BeLessThan ([double]::MaxValue) + + $results = get-random -minimum ([double]::MinValue) -maximum ([double]::MaxValue) + $results.GetType().FullName | Should Be System.Double + $results | Should BeGreaterThan ([double]::MinValue) + $results | Should BeLessThan ([double]::MaxValue) + + #Verify Error + { get-random -Minimum 20 -Maximum 10 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (10)" + { get-random -Minimum 20 -Maximum 20 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (20)" + { get-random -Minimum -10 -Maximum -20 } | Should Throw "The Minimum value (-10) cannot be greater than or equal to the Maximum value (-20)" + { get-random -Minimum -20 -Maximum -20 } | Should Throw "The Minimum value (-20) cannot be greater than or equal to the Maximum value (-20)" + { get-random -Minimum 20.0 -Maximum 10.0 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (10)" + { get-random -Minimum 20.0 -Maximum 20.0 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (20)" + { get-random -Minimum -10.0 -Maximum -20.0 } | Should Throw "The Minimum value (-10) cannot be greater than or equal to the Maximum value (-20)" + { get-random -Minimum -20.0 -Maximum -20.0 } | Should Throw "The Minimum value (-20) cannot be greater than or equal to the Maximum value (-20)" + { get-random -10 } | Should Throw "The Minimum value (0) cannot be greater than or equal to the Maximum value (-10)" + { $x = -10; get-random $x } | Should Throw "The Minimum value (0) cannot be greater than or equal to the Maximum value (-10)" + } + + It "Tests for setting the seed" { + $result1 = get-random -SetSeed 123; get-random; + $result2 = get-random -SetSeed 123; get-random; + $result1 | Should Be $result2 + } +} + Describe "Get-Random" { It "Should return a random number greater than -1 " { Get-Random | Should BeGreaterThan -1 From 01af13ce37245f3066637a7904ef42cb2fb4ad02 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Sun, 24 Apr 2016 20:14:40 -0700 Subject: [PATCH 2/4] Fix the issue of CR for Get-Random --- test/powershell/Get-Random.Tests.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/powershell/Get-Random.Tests.ps1 b/test/powershell/Get-Random.Tests.ps1 index f62cbebef..ac2088975 100644 --- a/test/powershell/Get-Random.Tests.ps1 +++ b/test/powershell/Get-Random.Tests.ps1 @@ -241,9 +241,13 @@ Describe "Get-Random DRT Unit Tests" -Tags DRT{ } It "Tests for setting the seed" { - $result1 = get-random -SetSeed 123; get-random; - $result2 = get-random -SetSeed 123; get-random; - $result1 | Should Be $result2 + $result1 = (get-random -SetSeed 123), (get-random) + $result2 = (get-random -SetSeed 123), (get-random) + $result1.Length | Should Be $result2.Length + for($i = 0;$i -lt $result1.Length;$i++) + { + $result1[$i] | Should Be $result2[$i] + } } } From d9ffecc36013d053a456117a8dffa4d4ffb6b348 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Tue, 26 Apr 2016 02:16:43 -0700 Subject: [PATCH 3/4] Fix the CR issue for Get-Random --- test/powershell/Get-Random.Tests.ps1 | 280 ++++++--------------------- 1 file changed, 56 insertions(+), 224 deletions(-) diff --git a/test/powershell/Get-Random.Tests.ps1 b/test/powershell/Get-Random.Tests.ps1 index ac2088975..d1bda6375 100644 --- a/test/powershell/Get-Random.Tests.ps1 +++ b/test/powershell/Get-Random.Tests.ps1 @@ -1,232 +1,64 @@ Describe "Get-Random DRT Unit Tests" -Tags DRT{ - - # -minimum is always set to the actual low end of the range, details refer to closed issue #887 - It "Tests for random-numbers mode" { - # Test for Int32 - $results = get-random - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan ([int32]::MaxValue) + $testData = @( + @{ Name = 'No params'; Maximum = $null; Minimum = $null; GreaterThan = -1; LessThan = ([int32]::MaxValue); Type = 'System.Int32' } + @{ Name = 'Just maximum: 100'; Maximum = 100; Minimum = $null; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'Just maximum: 10000'; Maximum = 10000; Minimum = $null; GreaterThan = -1; LessThan = 10000; Type = 'System.Int32' } + @{ Name = 'maximum:0, Minimum:-100'; Maximum = 0; Minimum = -100; GreaterThan = -101; LessThan = 0; Type = 'System.Int32' } + @{ Name = 'maximum:100, Minimum:-100'; Maximum = 100; Minimum = -100; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum:-100, Minimum:-200'; Maximum = -100; Minimum = -200; GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } + @{ Name = 'maximum:(-100), Minimum:(-200)'; Maximum = (-100); Minimum = (-200); GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } + @{ Name = 'maximum:8, Minimum:5'; Maximum = '8'; Minimum = 5; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } + @{ Name = 'maximum:8, Minimum:5'; Maximum = 8; Minimum = '5'; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } + @{ Name = 'maximum:+100, Minimum:0'; Maximum = +100; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum:+100, Minimum:0'; Maximum = '+100'; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum:+100, Minimum:-100'; Maximum = '+100'; Minimum = '-100'; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum:1kb, Minimum:0'; Maximum = '1kb'; Minimum = 0; GreaterThan = -1; LessThan = 1024; Type = 'System.Int32' } + @{ Name = 'Just maximum:MaxValue'; Maximum = ([int64]::MaxValue); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } + @{ Name = 'Just maximum:([int64]100)'; Maximum = ([int64]100); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'Just maximum:100000000000'; Maximum = 100000000000; Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100000000000); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]0), Minimum:([int64]-100)'; Maximum = ([int64]0); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]100), Minimum:([int64]-100)'; Maximum = ([int64]100); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]-100), Minimum:([int64]-200)'; Maximum = ([int64]-100); Minimum = ([int64]-200); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } + @{ Name = 'maximum:([int64](-100)), Minimum:([int64](-200))'; Maximum = ([int64](-100)); Minimum = ([int64](-200)); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } + @{ Name = 'maximum:8, Minimum:([int64]5)'; Maximum = '8'; Minimum = ([int64]5); GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]8), Minimum:5'; Maximum = ([int64]8); Minimum = '5'; GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } + @{ Name = 'maximum:+100, Minimum:([int64]0)'; Maximum = +100; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'maximum:+100, Minimum:([int64]0)'; Maximum = '+100'; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]0), Minimum:-100'; Maximum = ([int64]0); Minimum = '-100'; GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]1048585, Minimum:1mb'; Maximum = ([int64]1048585); Minimum = '1mb'; GreaterThan = ([int64]1048575); LessThan = ([int64]1048585); Type = 'System.Int64' } + @{ Name = 'maximum:1tb, Minimum:10mb'; Maximum = '1tb'; Minimum = '10mb'; GreaterThan = ([int64]10485759); LessThan = ([int64]1099511627776); Type = 'System.Int64' } + @{ Name = 'maximum:([int64]::MaxValue), Minimum:([int64]::MinValue)'; Maximum = ([int64]::MaxValue); Minimum = ([int64]::MinValue); GreaterThan = ([int64]::MinValue); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } + @{ Name = 'maximum:([int64](([int]::MaxValue)+15)), Minimum:([int64](([int]::MaxValue)+10))'; Maximum = ([int64](([int]::MaxValue)+15)); Minimum = ([int64](([int]::MaxValue)+10)); GreaterThan = ([int64](([int]::MaxValue)+9)); LessThan = ([int64](([int]::MaxValue)+15)); Type = 'System.Int64' } + @{ Name = 'maximum:([int64](([int]::MaxValue)+150)), Minimum:([int64](([int]::MaxValue)+100))'; Maximum = ([int64](([int]::MaxValue)+150)); Minimum = ([int64](([int]::MaxValue)+100)); GreaterThan = ([int64](([int]::MaxValue)+99)); LessThan = ([int64](([int]::MaxValue)+150)); Type = 'System.Int64' } + @{ Name = 'maximum:100099000001, Minimum:100000000001'; Maximum = '100099000001'; Minimum = 100000000001; GreaterThan = ([int64]10000000000); LessThan = ([int64]100099000001); Type = 'System.Int64' } + @{ Name = 'maximum:100000002230, Minimum:100000002222'; Maximum = 100000002230; Minimum = '100000002222'; GreaterThan = ([int64]100000002221); LessThan = ([int64]100000002230); Type = 'System.Int64' } + @{ Name = 'maximum:90000000000, Minimum:4'; Maximum = 90000000000; Minimum = 4; GreaterThan = ([int64]3); LessThan = ([int64]90000000000); Type = 'System.Int64' } + @{ Name = 'Just maximum:100.0'; Maximum = 100.0; Minimum = $null; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'maximum:0.0, Minimum:-100.0'; Maximum = 0.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 0.0; Type = 'System.Double' } + @{ Name = 'maximum:100.0, Minimum:-100.0'; Maximum = 100.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'maximum:8.0, Minimum:5'; Maximum = 8.0; Minimum = 5; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } + @{ Name = 'maximum:8, Minimum:5.0'; Maximum = 8; Minimum = 5.0; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } + @{ Name = 'maximum:20., Minimum:0.0'; Maximum = 20.; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } + @{ Name = 'maximum:20., Minimum:0.0'; Maximum = '20.'; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } + @{ Name = 'maximum:+100.0, Minimum:0'; Maximum = +100.0; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'maximum:+100.0, Minimum:0'; Maximum = '+100.0'; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'Just Minimum:1.0e+100'; Maximum = $null; Minimum = 1.0e+100; GreaterThan = 1.0e+99; LessThan = ([double]::MaxValue); Type = 'System.Double' } + @{ Name = 'maximum:([double]::MaxValue), Minimum:([double]::MinValue)'; Maximum = ([double]::MaxValue); Minimum = ([double]::MinValue); GreaterThan = ([double]::MinValue); LessThan = ([double]::MaxValue); Type = 'System.Double' } - $results = get-random 100 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan 100 + ) - $x = 10000 - $results = get-random $x - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan 10000 + # minimum is always set to the actual low end of the range, details refer to closed issue #887. + It "get a correct random number for ''" -TestCases $testData { + param($maximum, $minimum, $greaterThan, $lessThan, $type) - $results = get-random -Minimum -100 -Maximum 0 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -101 - $results | Should BeLessThan 0 - - $results = get-random -Minimum -100 -Maximum 100 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -101 - $results | Should BeLessThan 100 - - $results = get-random -Minimum -200 -Maximum -100 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -201 - $results | Should BeLessThan -100 - - $results = get-random -Minimum (-200) -Maximum (-100) - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -201 - $results | Should BeLessThan -100 - - $results = get-random -Minimum 5 -Maximum '8' - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan 4 - $results | Should BeLessThan 8 - - $results = get-random -Minimum '5' -Maximum 8 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan 4 - $results | Should BeLessThan 8 - - $results = get-random -Minimum 0 -Maximum +100 - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan 100 - - $results = get-random -Minimum 0 -Maximum '+100' - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan 100 - - $results = get-random -Minimum '-100' -Maximum '+100' - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -101 - $results | Should BeLessThan 100 - - $results = get-random -Minimum 0 -Maximum '1kb' - $results.GetType().FullName | Should Be System.Int32 - $results | Should BeGreaterThan -1 - $results | Should BeLessThan 1024 - - #Test for Int64 - $results = get-random ([int64]::MaxValue) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-1) - $results | Should BeLessThan ([int64]::MaxValue) - - $results = get-random ([int64]100) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-1) - $results | Should BeLessThan ([int64]100) - - $results = get-random 100000000000 - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-1) - $results | Should BeLessThan ([int64]100000000000) - - $results = get-random -Minimum ([int64]-100) -Maximum ([int64]0) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-101) - $results | Should BeLessThan ([int64]0) - - $results = get-random -Minimum ([int64]-100) -Maximum ([int64]100) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-101) - $results | Should BeLessThan ([int64]100) - - $results = get-random -Minimum ([int64]-200) -Maximum ([int64]-100) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-201) - $results | Should BeLessThan ([int64]-100) - - $results = get-random -Minimum ([int64](-200)) -Maximum ([int64](-100)) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-201) - $results | Should BeLessThan ([int64]-100) - - - $results = get-random -Minimum ([int64]5) -Maximum '8' - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]4) - $results | Should BeLessThan ([int64]8) - - $results = get-random -Minimum '5' -Maximum ([int64]8) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]4) - $results | Should BeLessThan ([int64]8) - - $results = get-random -Minimum ([int64]0) -Maximum +100 - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-1) - $results | Should BeLessThan ([int64]100) - - $results = get-random -Minimum ([int64]0) -Maximum '+100' - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-1) - $results | Should BeLessThan ([int64]100) - - $results = get-random -Minimum '-100' -Maximum ([int64]0) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]-101) - $results | Should BeLessThan ([int64]0) - - $results = get-random -Minimum '1mb' -Maximum ([int64]1048585) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]1048575) - $results | Should BeLessThan ([int64]1048585) - - $results = get-random -Minimum '10mb' -Maximum '1tb' - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]10485759) - $results | Should BeLessThan ([int64]1099511627776) - - $results = get-random -Minimum ([int64]::MinValue) -Maximum ([int64]::MaxValue) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]::MinValue) - $results | Should BeLessThan ([int64]::MaxValue) - - $results = get-random -Minimum ([int64](([int]::MaxValue)+10)) -Maximum ([int64](([int]::MaxValue)+15)) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]([int32]::MaxValue + 9)) - $results | Should BeLessThan ([int64]([int32]::MaxValue + 15)) - - $results = get-random -Minimum ([int64](([int]::MaxValue)+100)) -Maximum ([int64](([int]::MaxValue)+150)) - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]([int32]::MaxValue + 99)) - $results | Should BeLessThan ([int64]([int32]::MaxValue + 150)) - - $results = get-random -Minimum 100000000001 -Maximum '100099000001' - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]100000000000) - $results | Should BeLessThan ([int64]100099000001) - - $results = get-random -Minimum '100000002222' -Maximum 100000002230 - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]100000002221) - $results | Should BeLessThan ([int64]100000002230) - - $results = get-random -Minimum 4 -Maximum 90000000000 - $results.GetType().FullName | Should Be System.Int64 - $results | Should BeGreaterThan ([int64]3) - $results | Should BeLessThan ([int64]90000000000) - - #Test for double - $results = get-random 100.0 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -1.0 - $results | Should BeLessThan 100.0 - - $results = get-random -Minimum -100.0 -Maximum 0.0 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -101.0 - $results | Should BeLessThan 0.0 - - $results = get-random -Minimum -100.0 -Maximum 100.0 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -101.0 - $results | Should BeLessThan 100.0 - - $results = get-random -Minimum 5 -Maximum 8.0 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan 4.0 - $results | Should BeLessThan 8.0 - - $results = get-random -Minimum 5.0 -Maximum 8 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan 4.0 - $results | Should BeLessThan 8.0 - - $results = get-random -Minimum 0.0 -Maximum 20. - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -1.0 - $results | Should BeLessThan 20.0 - - $results = get-random -Minimum 0.0 -Maximum '20.' - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -1.0 - $results | Should BeLessThan 20.0 - - $results = get-random -Minimum 0 -Maximum +100.0 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -1.0 - $results | Should BeLessThan 100.0 - - $results = get-random -Minimum 0 -Maximum '+100.0' - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan -1.0 - $results | Should BeLessThan 100.0 - - $results = get-random -Minimum 1.0e+100 - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan 1.0e+99 - $results | Should BeLessThan ([double]::MaxValue) - - $results = get-random -minimum ([double]::MinValue) -maximum ([double]::MaxValue) - $results.GetType().FullName | Should Be System.Double - $results | Should BeGreaterThan ([double]::MinValue) - $results | Should BeLessThan ([double]::MaxValue) + $result = Get-Random -Maximum $maximum -Minimum $minimum + $result | Should BeGreaterThan $greaterThan + $result | Should BeLessThan $lessThan + $result.GetType().FullName | Should Be $type + } + + It "Tests for random-numbers mode" { #Verify Error { get-random -Minimum 20 -Maximum 10 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (10)" { get-random -Minimum 20 -Maximum 20 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (20)" From 3437566ebdb8edd8121b2d3835817aa38cbf96cb Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Thu, 5 May 2016 03:08:20 -0700 Subject: [PATCH 4/4] Fix the CR issues for Get-Random --- test/powershell/Get-Random.Tests.ps1 | 128 ++++++++++++++------------- 1 file changed, 67 insertions(+), 61 deletions(-) diff --git a/test/powershell/Get-Random.Tests.ps1 b/test/powershell/Get-Random.Tests.ps1 index d1bda6375..58cca7cb9 100644 --- a/test/powershell/Get-Random.Tests.ps1 +++ b/test/powershell/Get-Random.Tests.ps1 @@ -1,49 +1,60 @@ Describe "Get-Random DRT Unit Tests" -Tags DRT{ $testData = @( - @{ Name = 'No params'; Maximum = $null; Minimum = $null; GreaterThan = -1; LessThan = ([int32]::MaxValue); Type = 'System.Int32' } - @{ Name = 'Just maximum: 100'; Maximum = 100; Minimum = $null; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } - @{ Name = 'Just maximum: 10000'; Maximum = 10000; Minimum = $null; GreaterThan = -1; LessThan = 10000; Type = 'System.Int32' } - @{ Name = 'maximum:0, Minimum:-100'; Maximum = 0; Minimum = -100; GreaterThan = -101; LessThan = 0; Type = 'System.Int32' } - @{ Name = 'maximum:100, Minimum:-100'; Maximum = 100; Minimum = -100; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } - @{ Name = 'maximum:-100, Minimum:-200'; Maximum = -100; Minimum = -200; GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } - @{ Name = 'maximum:(-100), Minimum:(-200)'; Maximum = (-100); Minimum = (-200); GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } - @{ Name = 'maximum:8, Minimum:5'; Maximum = '8'; Minimum = 5; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } - @{ Name = 'maximum:8, Minimum:5'; Maximum = 8; Minimum = '5'; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } - @{ Name = 'maximum:+100, Minimum:0'; Maximum = +100; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } - @{ Name = 'maximum:+100, Minimum:0'; Maximum = '+100'; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } - @{ Name = 'maximum:+100, Minimum:-100'; Maximum = '+100'; Minimum = '-100'; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } - @{ Name = 'maximum:1kb, Minimum:0'; Maximum = '1kb'; Minimum = 0; GreaterThan = -1; LessThan = 1024; Type = 'System.Int32' } - @{ Name = 'Just maximum:MaxValue'; Maximum = ([int64]::MaxValue); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } - @{ Name = 'Just maximum:([int64]100)'; Maximum = ([int64]100); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } - @{ Name = 'Just maximum:100000000000'; Maximum = 100000000000; Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100000000000); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]0), Minimum:([int64]-100)'; Maximum = ([int64]0); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]100), Minimum:([int64]-100)'; Maximum = ([int64]100); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]100); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]-100), Minimum:([int64]-200)'; Maximum = ([int64]-100); Minimum = ([int64]-200); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } - @{ Name = 'maximum:([int64](-100)), Minimum:([int64](-200))'; Maximum = ([int64](-100)); Minimum = ([int64](-200)); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } - @{ Name = 'maximum:8, Minimum:([int64]5)'; Maximum = '8'; Minimum = ([int64]5); GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]8), Minimum:5'; Maximum = ([int64]8); Minimum = '5'; GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } - @{ Name = 'maximum:+100, Minimum:([int64]0)'; Maximum = +100; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } - @{ Name = 'maximum:+100, Minimum:([int64]0)'; Maximum = '+100'; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]0), Minimum:-100'; Maximum = ([int64]0); Minimum = '-100'; GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]1048585, Minimum:1mb'; Maximum = ([int64]1048585); Minimum = '1mb'; GreaterThan = ([int64]1048575); LessThan = ([int64]1048585); Type = 'System.Int64' } - @{ Name = 'maximum:1tb, Minimum:10mb'; Maximum = '1tb'; Minimum = '10mb'; GreaterThan = ([int64]10485759); LessThan = ([int64]1099511627776); Type = 'System.Int64' } - @{ Name = 'maximum:([int64]::MaxValue), Minimum:([int64]::MinValue)'; Maximum = ([int64]::MaxValue); Minimum = ([int64]::MinValue); GreaterThan = ([int64]::MinValue); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } - @{ Name = 'maximum:([int64](([int]::MaxValue)+15)), Minimum:([int64](([int]::MaxValue)+10))'; Maximum = ([int64](([int]::MaxValue)+15)); Minimum = ([int64](([int]::MaxValue)+10)); GreaterThan = ([int64](([int]::MaxValue)+9)); LessThan = ([int64](([int]::MaxValue)+15)); Type = 'System.Int64' } - @{ Name = 'maximum:([int64](([int]::MaxValue)+150)), Minimum:([int64](([int]::MaxValue)+100))'; Maximum = ([int64](([int]::MaxValue)+150)); Minimum = ([int64](([int]::MaxValue)+100)); GreaterThan = ([int64](([int]::MaxValue)+99)); LessThan = ([int64](([int]::MaxValue)+150)); Type = 'System.Int64' } - @{ Name = 'maximum:100099000001, Minimum:100000000001'; Maximum = '100099000001'; Minimum = 100000000001; GreaterThan = ([int64]10000000000); LessThan = ([int64]100099000001); Type = 'System.Int64' } - @{ Name = 'maximum:100000002230, Minimum:100000002222'; Maximum = 100000002230; Minimum = '100000002222'; GreaterThan = ([int64]100000002221); LessThan = ([int64]100000002230); Type = 'System.Int64' } - @{ Name = 'maximum:90000000000, Minimum:4'; Maximum = 90000000000; Minimum = 4; GreaterThan = ([int64]3); LessThan = ([int64]90000000000); Type = 'System.Int64' } - @{ Name = 'Just maximum:100.0'; Maximum = 100.0; Minimum = $null; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } - @{ Name = 'maximum:0.0, Minimum:-100.0'; Maximum = 0.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 0.0; Type = 'System.Double' } - @{ Name = 'maximum:100.0, Minimum:-100.0'; Maximum = 100.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 100.0; Type = 'System.Double' } - @{ Name = 'maximum:8.0, Minimum:5'; Maximum = 8.0; Minimum = 5; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } - @{ Name = 'maximum:8, Minimum:5.0'; Maximum = 8; Minimum = 5.0; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } - @{ Name = 'maximum:20., Minimum:0.0'; Maximum = 20.; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } - @{ Name = 'maximum:20., Minimum:0.0'; Maximum = '20.'; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } - @{ Name = 'maximum:+100.0, Minimum:0'; Maximum = +100.0; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } - @{ Name = 'maximum:+100.0, Minimum:0'; Maximum = '+100.0'; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } - @{ Name = 'Just Minimum:1.0e+100'; Maximum = $null; Minimum = 1.0e+100; GreaterThan = 1.0e+99; LessThan = ([double]::MaxValue); Type = 'System.Double' } - @{ Name = 'maximum:([double]::MaxValue), Minimum:([double]::MinValue)'; Maximum = ([double]::MaxValue); Minimum = ([double]::MinValue); GreaterThan = ([double]::MinValue); LessThan = ([double]::MaxValue); Type = 'System.Double' } + @{ Name = 'no params'; Maximum = $null; Minimum = $null; GreaterThan = -1; LessThan = ([int32]::MaxValue); Type = 'System.Int32' } + @{ Name = 'only positive maximum number'; Maximum = 100; Minimum = $null; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum set to 0, Minimum to a negative number'; Maximum = 0; Minimum = -100; GreaterThan = -101; LessThan = 0; Type = 'System.Int32' } + @{ Name = 'positive maximum, negative Minimum'; Maximum = 100; Minimum = -100; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'both negative'; Maximum = -100; Minimum = -200; GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } + @{ Name = 'both negative with parentheses'; Maximum = (-100); Minimum = (-200); GreaterThan = -201; LessThan = -100; Type = 'System.Int32' } + @{ Name = 'maximum enclosed in quote'; Maximum = '8'; Minimum = 5; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } + @{ Name = 'minimum enclosed in quote'; Maximum = 8; Minimum = '5'; GreaterThan = 4; LessThan = 8; Type = 'System.Int32' } + @{ Name = 'maximum with plus sign'; Maximum = +100; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum with plus sign and quote'; Maximum = '+100'; Minimum = 0; GreaterThan = -1; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'both with quote'; Maximum = '+100'; Minimum = '-100'; GreaterThan = -101; LessThan = 100; Type = 'System.Int32' } + @{ Name = 'maximum set to kb'; Maximum = '1kb'; Minimum = 0; GreaterThan = -1; LessThan = 1024; Type = 'System.Int32' } + @{ Name = 'maximum is Int64.MaxValue'; Maximum = ([int64]::MaxValue); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } + @{ Name = 'maximum is a 64-bit integer'; Maximum = ([int64]100); Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'maximum set to a large integer greater than int32.MaxValue'; Maximum = 100000000000; Minimum = $null; GreaterThan = ([int64]-1); LessThan = ([int64]100000000000); Type = 'System.Int64' } + @{ Name = 'maximum set to 0, Minumum set to a negative 64-bit integer'; Maximum = ([int64]0); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } + @{ Name = 'maximum set to positive 64-bit number, min set to negative 64-bit number'; Maximum = ([int64]100); Minimum = ([int64]-100); GreaterThan = ([int64]-101); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'both are negative 64-bit number'; Maximum = ([int64]-100); Minimum = ([int64]-200); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } + @{ Name = 'both are negative 64-bit number with parentheses'; Maximum = ([int64](-100)); Minimum = ([int64](-200)); GreaterThan = ([int64]-201); LessThan = ([int64]-100); Type = 'System.Int64' } + @{ Name = 'max is 32-bit, min is 64-bit integer'; Maximum = '8'; Minimum = ([int64]5); GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } + @{ Name = 'max is 64-bit, min is 32-bit integer'; Maximum = ([int64]8); Minimum = '5'; GreaterThan = ([int64]4); LessThan = ([int64]8); Type = 'System.Int64' } + @{ Name = 'max set to a 32-bit integer, min set to [int64]0'; Maximum = +100; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'max set to a 32-bit integer with quote'; Maximum = '+100'; Minimum = ([int64]0); GreaterThan = ([int64]-1); LessThan = ([int64]100); Type = 'System.Int64' } + @{ Name = 'max is [int64]0, min is a 32-bit integer'; Maximum = ([int64]0); Minimum = '-100'; GreaterThan = ([int64]-101); LessThan = ([int64]0); Type = 'System.Int64' } + @{ Name = 'min set to 1MB, max set to a 64-bit integer greater than min'; Maximum = ([int64]1048585); Minimum = '1mb'; GreaterThan = ([int64]1048575); LessThan = ([int64]1048585); Type = 'System.Int64' } + @{ Name = 'max set to 1tb, min set to 10 mb'; Maximum = '1tb'; Minimum = '10mb'; GreaterThan = ([int64]10485759); LessThan = ([int64]1099511627776); Type = 'System.Int64' } + @{ Name = 'max is int64.MaxValue, min is Int64.MinValue'; Maximum = ([int64]::MaxValue); Minimum = ([int64]::MinValue); GreaterThan = ([int64]::MinValue); LessThan = ([int64]::MaxValue); Type = 'System.Int64' } + @{ Name = 'both are int64.MaxValue plus a 32-bit integer'; Maximum = ([int64](([int]::MaxValue)+15)); Minimum = ([int64](([int]::MaxValue)+10)); GreaterThan = ([int64](([int]::MaxValue)+9)); LessThan = ([int64](([int]::MaxValue)+15)); Type = 'System.Int64' } + @{ Name = 'both are greater than int32.MaxValue without specified type, and max with quote'; Maximum = '100099000001'; Minimum = 100000000001; GreaterThan = ([int64]10000000000); LessThan = ([int64]100099000001); Type = 'System.Int64' } + @{ Name = 'both are greater than int32.MaxValue without specified type, and min with quote'; Maximum = 100000002230; Minimum = '100000002222'; GreaterThan = ([int64]100000002221); LessThan = ([int64]100000002230); Type = 'System.Int64' } + @{ Name = 'max is greater than int32.MaxValue without specified type'; Maximum = 90000000000; Minimum = 4; GreaterThan = ([int64]3); LessThan = ([int64]90000000000); Type = 'System.Int64' } + @{ Name = 'max is a double-precision number'; Maximum = 100.0; Minimum = $null; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'both are double-precision numbers, min is negative.'; Maximum = 0.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 0.0; Type = 'System.Double' } + @{ Name = 'both are double-precision number, max is positive, min is negative.'; Maximum = 100.0; Minimum = -100.0; GreaterThan = -101.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'max is a double-precision number, min is int32'; Maximum = 8.0; Minimum = 5; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } + @{ Name = 'min is a double-precision number, max is int32'; Maximum = 8; Minimum = 5.0; GreaterThan = 4.0; LessThan = 8.0; Type = 'System.Double' } + @{ Name = 'max set to a special double number'; Maximum = 20.; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } + @{ Name = 'max is double with quote'; Maximum = '20.'; Minimum = 0.0; GreaterThan = -1.0; LessThan = 20.0; Type = 'System.Double' } + @{ Name = 'max is double with plus sign'; Maximum = +100.0; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'max is doulbe with plus sign and enclosed in quote'; Maximum = '+100.0'; Minimum = 0; GreaterThan = -1.0; LessThan = 100.0; Type = 'System.Double' } + @{ Name = 'both set to the special numbers as 1.0e+xx '; Maximum = $null; Minimum = 1.0e+100; GreaterThan = 1.0e+99; LessThan = ([double]::MaxValue); Type = 'System.Double' } + @{ Name = 'max is Double.MaxValue, min is Double.MinValue'; Maximum = ([double]::MaxValue); Minimum = ([double]::MinValue); GreaterThan = ([double]::MinValue); LessThan = ([double]::MaxValue); Type = 'System.Double' } + + ) + + $testDataForError = @( + @{ Name = 'Min is greater than max and all are positive 32-bit integer'; Maximum = 10; Minimum = 20} + @{ Name = 'Min and Max are same and all are positive 32-bit integer'; Maximum = 20; Minimum = 20} + @{ Name = 'Min is greater than max and all are negative 32-bit integer'; Maximum = -20; Minimum = -10} + @{ Name = 'Min and Max are same and all are negative 32-bit integer'; Maximum = -20; Minimum = -20} + @{ Name = 'Min is greater than max and all are positive double-precision number'; Maximum = 10.0; Minimum = 20.0} + @{ Name = 'Min and Max are same and all are positive double-precision number'; Maximum = 20.0; Minimum = 20.0} + @{ Name = 'Min is greater than max and all are negative double-precision number'; Maximum = -20.0; Minimum = -10.0} + @{ Name = 'Min and Max are same and all are negative double-precision number'; Maximum = -20.0; Minimum = -20.0} + @{ Name = 'Max is a negative number, min is the default number '; Maximum = -10; Minimum = $null} ) @@ -58,28 +69,23 @@ Describe "Get-Random DRT Unit Tests" -Tags DRT{ } - It "Tests for random-numbers mode" { - #Verify Error - { get-random -Minimum 20 -Maximum 10 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (10)" - { get-random -Minimum 20 -Maximum 20 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (20)" - { get-random -Minimum -10 -Maximum -20 } | Should Throw "The Minimum value (-10) cannot be greater than or equal to the Maximum value (-20)" - { get-random -Minimum -20 -Maximum -20 } | Should Throw "The Minimum value (-20) cannot be greater than or equal to the Maximum value (-20)" - { get-random -Minimum 20.0 -Maximum 10.0 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (10)" - { get-random -Minimum 20.0 -Maximum 20.0 } | Should Throw "The Minimum value (20) cannot be greater than or equal to the Maximum value (20)" - { get-random -Minimum -10.0 -Maximum -20.0 } | Should Throw "The Minimum value (-10) cannot be greater than or equal to the Maximum value (-20)" - { get-random -Minimum -20.0 -Maximum -20.0 } | Should Throw "The Minimum value (-20) cannot be greater than or equal to the Maximum value (-20)" - { get-random -10 } | Should Throw "The Minimum value (0) cannot be greater than or equal to the Maximum value (-10)" - { $x = -10; get-random $x } | Should Throw "The Minimum value (0) cannot be greater than or equal to the Maximum value (-10)" + It "Should be able to throw error when ''" -TestCases $testDataForError { + param($maximum, $minimum) + try + { + Get-Random -Minimum $minimum -Maximum $maximum + throw "OK" + } + catch + { + $_.FullyQualifiedErrorId | Should Be "MinGreaterThanOrEqualMax,Microsoft.PowerShell.Commands.GetRandomCommand" + } } It "Tests for setting the seed" { $result1 = (get-random -SetSeed 123), (get-random) $result2 = (get-random -SetSeed 123), (get-random) - $result1.Length | Should Be $result2.Length - for($i = 0;$i -lt $result1.Length;$i++) - { - $result1[$i] | Should Be $result2[$i] - } + $result1 | Should Be $result2 } }