Skip to content

Commit

Permalink
Update test suites (#355)
Browse files Browse the repository at this point in the history
Update test suites regarding throwing error for more dynamic testing.

[no important files changed]
  • Loading branch information
glaxxie authored Feb 20, 2024
1 parent 58e6f75 commit 707dac4
Show file tree
Hide file tree
Showing 26 changed files with 90 additions and 91 deletions.
10 changes: 5 additions & 5 deletions exercises/practice/binary-search/BinarySearch.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ Describe "Test Invoke-BinarySearch.ps1" {

Context "Invalid Inputs" {
It "identifies that a value is not included in the array" {
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 7 } | Should -Throw "error: value not in array"
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 7 } | Should -Throw "*error: value not in array*"
}

It "identifies that a value smaller than the array's smallest value is not included in the array" {
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 0 } | Should -Throw "error: value not in array"
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 0 } | Should -Throw "*error: value not in array*"
}

It "identifies that a value larger than the array's largest value is not included in the array" {
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 13 } | Should -Throw "error: value not in array"
{ Invoke-BinarySearch -Array @(1, 3, 4, 6, 8, 9, 11) -Value 13 } | Should -Throw "*error: value not in array*"
}

It "nothing is found in an empty array" {
{ Invoke-BinarySearch -Array @() -Value 1 } | Should -Throw "error: value not in array"
{ Invoke-BinarySearch -Array @() -Value 1 } | Should -Throw "*error: value not in array*"
}

It "nothing is found when the left and right bounds cross" {
{ Invoke-BinarySearch -Array @(1, 2) -Value 0 } | Should -Throw "error: value not in array"
{ Invoke-BinarySearch -Array @(1, 2) -Value 0 } | Should -Throw "*error: value not in array*"
}
}
}
9 changes: 4 additions & 5 deletions exercises/practice/bottle-song/BottleSong.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,24 @@ Describe "BottleSong test cases" {
Context "Error: Invalid parameter inputs" {
It "start with too many bottles" {
$bottles = 50
$errMsg = "Cannot validate argument on parameter 'Start'. The $bottles argument is greater than the maximum allowed range of 10. Supply an argument that is less than or equal to 10 and then try the command again."
$errMsg = "*Cannot validate argument on parameter 'Start'. The $bottles argument is greater than the maximum allowed range of 10. Supply an argument that is less than or equal to 10 and then try the command again.*"
{ Get-Lyric -Start $bottles } | Should -Throw $errMsg
}

It "start with less than one bottle" {
$bottles = 0
$errMsg = "Cannot validate argument on parameter 'Start'. The $bottles argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again."
$errMsg = "*Cannot validate argument on parameter 'Start'. The $bottles argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again.*"
{ Get-Lyric -Start $bottles } | Should -Throw $errMsg
}

It "taking less than one bottle" {
$bottles = -1
$errMsg = "Cannot validate argument on parameter 'Take'. The $bottles argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again."
$errMsg = "*Cannot validate argument on parameter 'Take'. The $bottles argument is less than the minimum allowed range of 1. Supply an argument that is greater than or equal to 1 and then try the command again.*"
{ Get-Lyric -Start 3 -Take $bottles } | Should -Throw $errMsg
}

It "taking more bottle than available" {
$errMsg = "Cannot validate argument on parameter 'Take'. You can't take more bottle than what you started with."
{ Get-Lyric -Start 3 -Take 5 } | Should -Throw $errMsg
{ Get-Lyric -Start 3 -Take 5 } | Should -Throw "*You can't take more bottle than what you started with.*"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/change/Change.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ Describe "coin change test cases" {

Context "invalid inputs" {
It "error testing for change smaller than the smallest of coins" {
{Get-Change -Coins @(5, 10) -Target 3} | Should -Throw "Can't make change with given coins"
{Get-Change -Coins @(5, 10) -Target 3} | Should -Throw "*Can't make change with given coins*"
}

It "error if no combination can add up to target" {
{Get-Change -Coins @(5, 10) -Target 27} | Should -Throw "Can't make change with given coins"
{Get-Change -Coins @(5, 10) -Target 27} | Should -Throw "*Can't make change with given coins*"
}

It "cannot find negative change values" {
{Get-Change -Coins @(5, 10) -Target -2} | Should -Throw "Target can't be negative"
{Get-Change -Coins @(5, 10) -Target -2} | Should -Throw "*Target can't be negative*"
}
}
}
10 changes: 5 additions & 5 deletions exercises/practice/circular-buffer/CircularBuffer.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BeforeAll {
Describe "CircularBuffer test cases" {
It "reading empty buffer should fail" {
$buffer = [CircularBuffer]::new(1)
{ $buffer.Read() } | Should -Throw "BufferError: Circular buffer is empty"
{ $buffer.Read() } | Should -Throw "*BufferError: Circular buffer is empty*"
}

It "can read an item just written" {
Expand All @@ -18,7 +18,7 @@ Describe "CircularBuffer test cases" {
$buffer = [CircularBuffer]::new(1)
$buffer.Write(1)
$buffer.Read() | Should -BeExactly 1
{ $buffer.Read() } | Should -Throw "BufferError: Circular buffer is empty"
{ $buffer.Read() } | Should -Throw "*BufferError: Circular buffer is empty*"
}

It "items are read in the order they are written" {
Expand All @@ -32,7 +32,7 @@ Describe "CircularBuffer test cases" {
It "full buffer can't be written to" {
$buffer = [CircularBuffer]::new(5)
1..5 | ForEach-Object {$buffer.Write($_)}
{ $buffer.Write(6) } | Should -Throw "BufferError: Circular buffer is full"
{ $buffer.Write(6) } | Should -Throw "*BufferError: Circular buffer is full*"
}

It "a read frees up capacity for another write" {
Expand All @@ -57,7 +57,7 @@ Describe "CircularBuffer test cases" {
$buffer = [CircularBuffer]::new(1)
$buffer.Write(1)
$buffer.Clear()
{ $buffer.Read() } | Should -Throw "BufferError: Circular buffer is empty"
{ $buffer.Read() } | Should -Throw "*BufferError: Circular buffer is empty*"
}

It "clear frees up capacity for another write" {
Expand Down Expand Up @@ -114,6 +114,6 @@ Describe "CircularBuffer test cases" {
$buffer.Overwrite(4)
$buffer.Read() | Should -BeExactly 3
$buffer.Read() | Should -BeExactly 4
{ $buffer.Read() } | Should -Throw "BufferError: Circular buffer is empty"
{ $buffer.Read() } | Should -Throw "*BufferError: Circular buffer is empty*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Describe "Test Invoke-CollatzConjecture.ps1" {

Context "Invalid Inputs" {
It "zero is an error" {
{ Invoke-CollatzConjecture -Number 0 } | Should -Throw "error: Only positive numbers are allowed"
{ Invoke-CollatzConjecture -Number 0 } | Should -Throw "*error: Only positive numbers are allowed*"
}

It "negative value is an error" {
{ Invoke-CollatzConjecture -Number -15 } | Should -Throw "error: Only positive numbers are allowed"
{ Invoke-CollatzConjecture -Number -15 } | Should -Throw "*error: Only positive numbers are allowed*"
}
}
}
6 changes: 3 additions & 3 deletions exercises/practice/grains/Grains.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ Describe "Test Grains.ps1" {

Context "Invalid Inputs" {
It "zero is an error" {
{ Get-GrainSquare -Number 0 } | Should -Throw "square must be between 1 and 64"
{ Get-GrainSquare -Number 0 } | Should -Throw "*square must be between 1 and 64*"
}

It "negative value is an error" {
{ Get-GrainSquare -Number -1 } | Should -Throw "square must be between 1 and 64"
{ Get-GrainSquare -Number -1 } | Should -Throw "*square must be between 1 and 64*"
}

It "exceeds maximum square" {
{ Get-GrainSquare -Number 65 } | Should -Throw "square must be between 1 and 64"
{ Get-GrainSquare -Number 65 } | Should -Throw "*square must be between 1 and 64*"
}
}
}
8 changes: 4 additions & 4 deletions exercises/practice/hamming/HammingDifference.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ Describe "Get-Hamming Test cases" {

Context "Invalid Inputs" {
It "disallow first strand longer" {
{ Get-HammingDifference "AATG" "AAA" } | Should -Throw "strands must be of equal length."
{ Get-HammingDifference "AATG" "AAA" } | Should -Throw "*strands must be of equal length.*"
}

It "disallow second strand longer" {
{ Get-HammingDifference "ATA" "AGTG" } | Should -Throw "strands must be of equal length."
{ Get-HammingDifference "ATA" "AGTG" } | Should -Throw "*strands must be of equal length.*"
}

It "disallow left empty strand" {
{ Get-HammingDifference "" "G" } | Should -Throw "strands must be of equal length."
{ Get-HammingDifference "" "G" } | Should -Throw "*strands must be of equal length.*"
}

It "disallow right empty strand" {
{ Get-HammingDifference "G" "" } | Should -Throw "strands must be of equal length."
{ Get-HammingDifference "G" "" } | Should -Throw "*strands must be of equal length.*"
}
}
}
4 changes: 2 additions & 2 deletions exercises/practice/hangman/Hangman.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Describe "Hangman test cases" {
$game.Guess("x")
}
$game.GetStatus() | Should -BeExactly LOSE
{$game.Guess("x")} | Should -Throw "The game has already ended."
{$game.Guess("x")} | Should -Throw "*The game has already ended.*"
}

It "test feeding a correct letter removes underscores" {
Expand Down Expand Up @@ -82,7 +82,7 @@ Describe "Hangman test cases" {
$game.GetStatus() | Should -BeExactly WIN
$game.Display() | Should -BeExactly "hello"

{$game.Guess("x")} | Should -Throw "The game has already ended."
{$game.Guess("x")} | Should -Throw "*The game has already ended.*"
}

It "test winning on last guess still counts as a win" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ Describe "Test LargestSeriesProduct Cases" {

Context "Invalid Inputs" {
It "rejects span longer than string length" {
{ Get-LargestSeriesProduct -Digits "123" -Span 4 } | Should -Throw "span must be smaller than string length"
{ Get-LargestSeriesProduct -Digits "123" -Span 4 } | Should -Throw "*span must be smaller than string length*"
}

It "rejects empty string and nonzero span" {
{ Get-LargestSeriesProduct -Digits "" -Span 2 } | Should -Throw "span must be smaller than string length"
{ Get-LargestSeriesProduct -Digits "" -Span 2 } | Should -Throw "*span must be smaller than string length*"
}

It "rejects invalid character in digits" {
{ Get-LargestSeriesProduct -Digits "12e456T" -Span 3 } | Should -Throw "digits input must only contain digits"
{ Get-LargestSeriesProduct -Digits "12e456T" -Span 3 } | Should -Throw "*digits input must only contain digits*"
}

It "rejects negative span" {
{ Get-LargestSeriesProduct -Digits "1234" -Span -2 } | Should -Throw "span must not be negative"
{ Get-LargestSeriesProduct -Digits "1234" -Span -2 } | Should -Throw "*span must not be negative*"
}
}
}
2 changes: 1 addition & 1 deletion exercises/practice/nth-prime/NthPrime.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Describe "NthPrime Tests" {

Context "Invalid Inputs" {
It "there is no zeroth prime" {
{ Get-NthPrime -Number 0 } | Should -Throw "error: there is no zeroth prime"
{ Get-NthPrime -Number 0 } | Should -Throw "*error: there is no zeroth prime*"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ Describe "NucleotideCountTests" {
}

It "strand with invalid nucleotides" {
{ Get-NucleotideCount -Strand "AGXXACT" } | Should -Throw "Invalid nucleotide in strand"
{ Get-NucleotideCount -Strand "AGXXACT" } | Should -Throw "*Invalid nucleotide in strand*"
}
}
4 changes: 2 additions & 2 deletions exercises/practice/ocr-numbers/OcrNumbers.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Describe "OcrNumbers test cases" {
"| |",
" "
)
{ Invoke-OCR -Grid $lines } | Should -Throw "Number of input lines is not a multiple of four"
{ Invoke-OCR -Grid $lines } | Should -Throw "*Number of input lines is not a multiple of four*"
}

It "Input with a number of columns that is not a multiple of three raises an error" {
Expand All @@ -225,7 +225,7 @@ Describe "OcrNumbers test cases" {
" |",
" "
)
{ Invoke-OCR -Grid $lines } | Should -Throw "Number of input columns is not a multiple of three"
{ Invoke-OCR -Grid $lines } | Should -Throw "*Number of input columns is not a multiple of three*"
}
}

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/perfect-numbers/PerfectNumbers.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ Describe "Test Invoke-PerfectNumbers.ps1" {

Context "Invalid Inputs" {
It "Zero is rejected (not a natural number)" {
{ Invoke-PerfectNumbers -Number 0 } | Should -Throw "error: Classification is only possible for positive integers."
{ Invoke-PerfectNumbers -Number 0 } | Should -Throw "*error: Classification is only possible for positive integers.*"
}

It "Negative integer is rejected (not a natural number)" {
{ Invoke-PerfectNumbers -Number -1 } | Should -Throw "error: Classification is only possible for positive integers."
{ Invoke-PerfectNumbers -Number -1 } | Should -Throw "*error: Classification is only possible for positive integers.*"
}
}
}
26 changes: 13 additions & 13 deletions exercises/practice/phone-number/PhoneNumber.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,55 +63,55 @@ Describe "Phone Number Test Cases" {

Context "Invalid inputs" {
It "invalid when 9 digits" {
{ Get-PhoneNumber -Number '223456789' } | Should -Throw "Number can't be fewer than 10 digits"
{ Get-PhoneNumber -Number '223456789' } | Should -Throw "*Number can't be fewer than 10 digits*"
}

It "invalid when 11 digits does not start with a 1" {
{ Get-PhoneNumber -Number '+02234567890' } | Should -Throw '11 digits must start with 1'
{ Get-PhoneNumber -Number '+02234567890' } | Should -Throw "*11 digits must start with 1*"
}

It "invalid when more than 11 digits" {
{ Get-PhoneNumber -Number '123456789011' } | Should -Throw "Number can't be more than 11 digits"
{ Get-PhoneNumber -Number '123456789011' } | Should -Throw "*Number can't be more than 11 digits*"
}

It "invalid with letters" {
{ Get-PhoneNumber -Number 'tel-456-7890' } | Should -Throw 'Letters not permitted'
{ Get-PhoneNumber -Number 'tel-456-7890' } | Should -Throw "*Letters not permitted*"
}

It "invalid with punctuations" {
{ Get-PhoneNumber -Number '123-@:!-7890' } | Should -Throw 'Punctuations not permitted'
{ Get-PhoneNumber -Number '123-@:!-7890' } | Should -Throw "*Punctuations not permitted*"
}

It "invalid if area code starts with 0" {
{ Get-PhoneNumber -Number '(023) 456-7890' } | Should -Throw "Area code can't start with 0"
{ Get-PhoneNumber -Number '(023) 456-7890' } | Should -Throw "*Area code can't start with 0*"
}

It "invalid if area code starts with 1" {
{ Get-PhoneNumber -Number '(123) 456-7890' } | Should -Throw "Area code can't start with 1"
{ Get-PhoneNumber -Number '(123) 456-7890' } | Should -Throw "*Area code can't start with 1*"
}

It "invalid if exchange code starts with 0" {
{ Get-PhoneNumber -Number '223-056-7890' } | Should -Throw "Exchange code can't start with 0"
{ Get-PhoneNumber -Number '223-056-7890' } | Should -Throw "*Exchange code can't start with 0*"
}

It "invalid if exchange code starts with 1" {
{Get-PhoneNumber -Number '223-156-7890'} | Should -Throw "Exchange code can't start with 1"
{Get-PhoneNumber -Number '223-156-7890'} | Should -Throw "*Exchange code can't start with 1*"
}

It "invalid if area code starts with 0 on valid 11-digit number" {
{ Get-PhoneNumber -Number '+1 (023) 456-7890' } | Should -Throw "Area code can't start with 0"
{ Get-PhoneNumber -Number '+1 (023) 456-7890' } | Should -Throw "*Area code can't start with 0*"
}

It "invalid if area code starts with 1 on valid 11-digit number" {
{ Get-PhoneNumber -Number '+1 (123) 456-7890' } | Should -Throw "Area code can't start with 1"
{ Get-PhoneNumber -Number '+1 (123) 456-7890' } | Should -Throw "*Area code can't start with 1*"
}

It "invalid if exchange code starts with 0 on valid 11-digit number" {
{ Get-PhoneNumber -Number '+1 (223) 056-7890' } | Should -Throw "Exchange code can't start with 0"
{ Get-PhoneNumber -Number '+1 (223) 056-7890' } | Should -Throw "*Exchange code can't start with 0*"
}

It "invalid if exchange code starts with 1 on valid 11-digit number" {
{ Get-PhoneNumber -Number '+1 (223) 156-7890' } | Should -Throw "Exchange code can't start with 1"
{ Get-PhoneNumber -Number '+1 (223) 156-7890' } | Should -Throw "*Exchange code can't start with 1*"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ Describe "Test Invoke-ProteinTranslation.ps1" {

Context "Invalid Inputs" {
It "Non-existing codon can't translate" {
{ Invoke-ProteinTranslation -Strand "AAA" } | Should -Throw "error: Invalid codon"
{ Invoke-ProteinTranslation -Strand "AAA" } | Should -Throw "*error: Invalid codon*"
}

It "Unknown amino acids, not part of a codon, can't translate" {
{ Invoke-ProteinTranslation -Strand "XYZ" } | Should -Throw "error: Invalid codon"
{ Invoke-ProteinTranslation -Strand "XYZ" } | Should -Throw "*error: Invalid codon*"
}

It "Incomplete RNA sequence can't translate" {
{ Invoke-ProteinTranslation -Strand "AUGU" } | Should -Throw "error: Invalid codon"
{ Invoke-ProteinTranslation -Strand "AUGU" } | Should -Throw "*error: Invalid codon*"
}
}
}
10 changes: 5 additions & 5 deletions exercises/practice/queen-attack/QueenAttack.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ Describe "Queen Attack Test Cases" {

Context "Invalid inputs" {
It "queen must have positive row" {
{ [ChessBoard]::new(@(-2,3), @(1,4)) } | Should -Throw 'White queen must be placed on the board'
{ [ChessBoard]::new(@(-2,3), @(1,4)) } | Should -Throw "*White queen must be placed on the board*"
}

It "queen must have row on board" {
{ [ChessBoard]::new(@(3,3), @(8,4)) } | Should -Throw 'Black queen must be placed on the board'
{ [ChessBoard]::new(@(3,3), @(8,4)) } | Should -Throw "*Black queen must be placed on the board*"
}

It "queen must have positive column" {
{ [ChessBoard]::new(@(3,-1), @(5,2)) } | Should -Throw 'White queen must be placed on the board'
{ [ChessBoard]::new(@(3,-1), @(5,2)) } | Should -Throw "*White queen must be placed on the board*"
}

It "queen must have column on board" {
{ [ChessBoard]::new(@(3,2), @(4,9)) } | Should -Throw 'Black queen must be placed on the board'
{ [ChessBoard]::new(@(3,2), @(4,9)) } | Should -Throw "*Black queen must be placed on the board*"
}

It "queens can't occupy same space" {
{ [ChessBoard]::new(@(1,1), @(1,1)) } | Should -Throw 'Queens can not share the same space'
{ [ChessBoard]::new(@(1,1), @(1,1)) } | Should -Throw "*Queens can not share the same space*"
}
}
}
Loading

0 comments on commit 707dac4

Please sign in to comment.