mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-10 04:07:14 -06:00
PowerShell - bob
This commit is contained in:
23
powershell/bob/.exercism/config.json
Normal file
23
powershell/bob/.exercism/config.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
|
||||||
|
"authors": [
|
||||||
|
"gyssels"
|
||||||
|
],
|
||||||
|
"contributors": [
|
||||||
|
"kchenery",
|
||||||
|
"sjwarner"
|
||||||
|
],
|
||||||
|
"files": {
|
||||||
|
"solution": [
|
||||||
|
"BobResponse.ps1"
|
||||||
|
],
|
||||||
|
"test": [
|
||||||
|
"BobResponse.tests.ps1"
|
||||||
|
],
|
||||||
|
"example": [
|
||||||
|
".meta/BobResponse.example.ps1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
|
||||||
|
"source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
|
||||||
|
}
|
||||||
1
powershell/bob/.exercism/metadata.json
Normal file
1
powershell/bob/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"track":"powershell","exercise":"bob","id":"daf373bca9aa46f683be795880357358","url":"https://exercism.org/tracks/powershell/exercises/bob","handle":"Xevion","is_requester":true,"auto_approve":false}
|
||||||
1
powershell/bob/.version
Normal file
1
powershell/bob/.version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
47
powershell/bob/BobResponse.ps1
Normal file
47
powershell/bob/BobResponse.ps1
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
Function Get-BobResponse() {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
|
||||||
|
|
||||||
|
Bob answers 'Sure.' if you ask him a question.
|
||||||
|
|
||||||
|
He answers 'Whoa, chill out!' if you yell at him.
|
||||||
|
|
||||||
|
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
|
||||||
|
|
||||||
|
He says 'Fine. Be that way!' if you address him without actually saying
|
||||||
|
anything.
|
||||||
|
|
||||||
|
He answers 'Whatever.' to anything else.
|
||||||
|
|
||||||
|
.PARAMETER HeyBob
|
||||||
|
The sentence you say to Bob.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-BobResponse -HeyBob "Hi Bob"
|
||||||
|
#>
|
||||||
|
[CmdletBinding()]
|
||||||
|
Param(
|
||||||
|
[string]$HeyBob
|
||||||
|
)
|
||||||
|
|
||||||
|
# Not a single lowercase letter in the entire string
|
||||||
|
if (($HeyBob -cnotmatch '[a-z]') -and ($HeyBob -match '[A-Z]')) {
|
||||||
|
if ($HeyBob -match '\?$') {
|
||||||
|
return 'Calm down, I know what I''m doing!'
|
||||||
|
} else {
|
||||||
|
return 'Whoa, chill out!'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ends with question mark
|
||||||
|
if ($HeyBob -match '\?\s*$') { return 'Sure.' }
|
||||||
|
|
||||||
|
# 0 or more whitespace characters from start to end
|
||||||
|
if ($HeyBob -match '^\s*$') { return 'Fine. Be that way!'}
|
||||||
|
|
||||||
|
return 'Whatever.'
|
||||||
|
}
|
||||||
109
powershell/bob/BobResponse.tests.ps1
Normal file
109
powershell/bob/BobResponse.tests.ps1
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
BeforeAll {
|
||||||
|
. ".\BobResponse.ps1"
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "Test Get-BobResponse" {
|
||||||
|
|
||||||
|
It "stating something" {
|
||||||
|
Get-BobResponse -HeyBob "Tom-ay-to, tom-aaaah-to." | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "shouting" {
|
||||||
|
Get-BobResponse -HeyBob "WATCH OUT!" | Should -BeExactly "Whoa, chill out!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "shouting gibberish" {
|
||||||
|
Get-BobResponse -HeyBob "FCECDFCAAB" | Should -BeExactly "Whoa, chill out!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "asking a question" {
|
||||||
|
Get-BobResponse -HeyBob "Does this cryogenic chamber make me look fat?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "asking a numeric question" {
|
||||||
|
Get-BobResponse -HeyBob "You are, what, like 15?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "asking gibberish" {
|
||||||
|
Get-BobResponse -HeyBob "fffbbcbeab?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "talking forcefully" {
|
||||||
|
Get-BobResponse -HeyBob "Let's go make out behind the gym!" | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "using acronyms in regular speech" {
|
||||||
|
Get-BobResponse -HeyBob "It's OK if you don't want to go to the DMV." | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "forceful question" {
|
||||||
|
Get-BobResponse -HeyBob "WHAT THE HELL WERE YOU THINKING?" | Should -BeExactly "Calm down, I know what I'm doing!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "shouting numbers" {
|
||||||
|
Get-BobResponse -HeyBob "1, 2, 3 GO!" | Should -BeExactly "Whoa, chill out!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "only numbers" {
|
||||||
|
Get-BobResponse -HeyBob "1, 2, 3" | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "question with only numbers" {
|
||||||
|
Get-BobResponse -HeyBob "4?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "shouting with special characters" {
|
||||||
|
Get-BobResponse -HeyBob "ZOMG THE %^*@#`$(*^ ZOMBIES ARE COMING!!11!!1!" | Should -BeExactly "Whoa, chill out!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "shouting with no exclamation mark" {
|
||||||
|
Get-BobResponse -HeyBob "I HATE YOU" | Should -BeExactly "Whoa, chill out!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "statement containing question mark" {
|
||||||
|
Get-BobResponse -HeyBob "Ending with ? means a question." | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "non-letters with question" {
|
||||||
|
Get-BobResponse -HeyBob ":) ?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "prattling on" {
|
||||||
|
Get-BobResponse -HeyBob "Wait! Hang on. Are you going to be OK?" | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "silence" {
|
||||||
|
Get-BobResponse -HeyBob "" | Should -BeExactly "Fine. Be that way!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "prolonged silence" {
|
||||||
|
Get-BobResponse -HeyBob " " | Should -BeExactly "Fine. Be that way!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "alternate silence" {
|
||||||
|
Get-BobResponse -HeyBob " " | Should -BeExactly "Fine. Be that way!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "multiple line question" {
|
||||||
|
Get-BobResponse -HeyBob "
|
||||||
|
Does this cryogenic chamber make me look fat?
|
||||||
|
no" | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "starting with whitespace" {
|
||||||
|
Get-BobResponse -HeyBob " hmmmmmmm..." | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "ending with whitespace" {
|
||||||
|
Get-BobResponse -HeyBob "Okay if like my spacebar quite a bit? " | Should -BeExactly "Sure."
|
||||||
|
}
|
||||||
|
|
||||||
|
It "other whitespace" {
|
||||||
|
Get-BobResponse -HeyBob "
|
||||||
|
" | Should -BeExactly "Fine. Be that way!"
|
||||||
|
}
|
||||||
|
|
||||||
|
It "non-question ending with whitespace" {
|
||||||
|
Get-BobResponse -HeyBob "This is a statement ending with whitespace " | Should -BeExactly "Whatever."
|
||||||
|
}
|
||||||
|
}
|
||||||
33
powershell/bob/HELP.md
Normal file
33
powershell/bob/HELP.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Help
|
||||||
|
|
||||||
|
## Running the tests
|
||||||
|
|
||||||
|
To run the tests run the command `Invoke-Pester` from within the exercise directory.
|
||||||
|
|
||||||
|
## Submitting your solution
|
||||||
|
|
||||||
|
You can submit your solution using the `exercism submit BobResponse.ps1` command.
|
||||||
|
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||||
|
|
||||||
|
It's possible to submit an incomplete solution which allows you to:
|
||||||
|
|
||||||
|
- See how others have completed the exercise
|
||||||
|
- Request help from a mentor
|
||||||
|
|
||||||
|
## Need to get help?
|
||||||
|
|
||||||
|
If you'd like help solving the exercise, check the following pages:
|
||||||
|
|
||||||
|
- The [PowerShell track's documentation](https://exercism.org/docs/tracks/powershell)
|
||||||
|
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
|
||||||
|
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||||
|
|
||||||
|
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||||
|
|
||||||
|
To get help if you are having trouble, you can use one of the following resources:
|
||||||
|
|
||||||
|
- [Powershell Documentation][powershell docs]
|
||||||
|
|
||||||
|
[Add more resources]: TODO
|
||||||
|
|
||||||
|
[powershell docs]: https://docs.microsoft.com/en-us/powershell/
|
||||||
36
powershell/bob/README.md
Normal file
36
powershell/bob/README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Bob
|
||||||
|
|
||||||
|
Welcome to Bob on Exercism's PowerShell Track.
|
||||||
|
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
|
||||||
|
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
|
||||||
|
|
||||||
|
Bob answers 'Sure.' if you ask him a question, such as "How are you?".
|
||||||
|
|
||||||
|
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
|
||||||
|
|
||||||
|
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
|
||||||
|
|
||||||
|
He says 'Fine. Be that way!' if you address him without actually saying
|
||||||
|
anything.
|
||||||
|
|
||||||
|
He answers 'Whatever.' to anything else.
|
||||||
|
|
||||||
|
Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
|
||||||
|
|
||||||
|
## Source
|
||||||
|
|
||||||
|
### Created by
|
||||||
|
|
||||||
|
- @gyssels
|
||||||
|
|
||||||
|
### Contributed to by
|
||||||
|
|
||||||
|
- @kchenery
|
||||||
|
- @sjwarner
|
||||||
|
|
||||||
|
### Based on
|
||||||
|
|
||||||
|
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06
|
||||||
Reference in New Issue
Block a user