mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-09 12:07:08 -06:00
PowerShell - leap, raindrops, reverse-string, two-fer
This commit is contained in:
23
powershell/two-fer/.exercism/config.json
Normal file
23
powershell/two-fer/.exercism/config.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"blurb": "Create a sentence of the form \"One for X, one for me.\"",
|
||||
"authors": [
|
||||
"gyssels"
|
||||
],
|
||||
"contributors": [
|
||||
"cmccandless",
|
||||
"kchenery",
|
||||
"sjwarner"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"TwoFer.ps1"
|
||||
],
|
||||
"test": [
|
||||
"TwoFer.tests.ps1"
|
||||
],
|
||||
"example": [
|
||||
".meta/TwoFer.example.ps1"
|
||||
]
|
||||
},
|
||||
"source_url": "https://github.com/exercism/problem-specifications/issues/757"
|
||||
}
|
||||
1
powershell/two-fer/.exercism/metadata.json
Normal file
1
powershell/two-fer/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"powershell","exercise":"two-fer","id":"ee6acfe67bf6423e8ceab007e73d57ac","url":"https://exercism.org/tracks/powershell/exercises/two-fer","handle":"Xevion","is_requester":true,"auto_approve":false}
|
||||
1
powershell/two-fer/.version
Normal file
1
powershell/two-fer/.version
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
33
powershell/two-fer/HELP.md
Normal file
33
powershell/two-fer/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 TwoFer.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/
|
||||
47
powershell/two-fer/README.md
Normal file
47
powershell/two-fer/README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Two Fer
|
||||
|
||||
Welcome to Two Fer on Exercism's PowerShell Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
|
||||
|
||||
Given a name, return a string with the message:
|
||||
|
||||
```text
|
||||
One for name, one for me.
|
||||
```
|
||||
|
||||
Where "name" is the given name.
|
||||
|
||||
However, if the name is missing, return the string:
|
||||
|
||||
```text
|
||||
One for you, one for me.
|
||||
```
|
||||
|
||||
Here are some examples:
|
||||
|
||||
|Name |String to return
|
||||
|:-------|:------------------
|
||||
|Alice |One for Alice, one for me.
|
||||
|Bob |One for Bob, one for me.
|
||||
| |One for you, one for me.
|
||||
|Zaphod |One for Zaphod, one for me.
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @gyssels
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @cmccandless
|
||||
- @kchenery
|
||||
- @sjwarner
|
||||
|
||||
### Based on
|
||||
|
||||
https://github.com/exercism/problem-specifications/issues/757
|
||||
32
powershell/two-fer/TwoFer.ps1
Normal file
32
powershell/two-fer/TwoFer.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
Function Get-TwoFer(){
|
||||
<#
|
||||
.SYNOPSIS
|
||||
"Two-fer" is short for two for one. One for you and one for me.
|
||||
|
||||
.DESCRIPTION
|
||||
If the given name is "Alice", the result should be "One for Alice, one for me."
|
||||
If no name is given, the result should be "One for you, one for me."
|
||||
|
||||
.PARAMETER Name
|
||||
The name to use.
|
||||
|
||||
.EXAMPLE
|
||||
Get-TwoFer
|
||||
|
||||
Will return: One for you, one for me
|
||||
|
||||
.EXAMPLE
|
||||
Get-TwoFer -Name Alice
|
||||
|
||||
Will return: One for Alice, one for me
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$false, Position=0)]
|
||||
[string]$Name
|
||||
)
|
||||
|
||||
# if ($Name -eq $null -or $Name.Length -eq 0) { $Name = 'you'}
|
||||
if ([string]::IsNullOrEmpty($Name)) { $Name = 'you' }
|
||||
return "One for $($Name), one for me"
|
||||
}
|
||||
18
powershell/two-fer/TwoFer.tests.ps1
Normal file
18
powershell/two-fer/TwoFer.tests.ps1
Normal file
@@ -0,0 +1,18 @@
|
||||
BeforeAll {
|
||||
. ".\TwoFer.ps1"
|
||||
}
|
||||
|
||||
Describe "Get-TwoFer Tests" {
|
||||
|
||||
It "Given <Name> expects <Expected>" -TestCases @(
|
||||
@{ Name = $null; Expected = "One for you, one for me" },
|
||||
@{ Name = ""; Expected = "One for you, one for me" },
|
||||
@{ Name = "Alice"; Expected = "One for Alice, one for me" }
|
||||
) {
|
||||
Param(
|
||||
$Name, $Expected
|
||||
)
|
||||
|
||||
Get-TwoFer -Name $Name | Should -Be $Expected
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user