PowerShell - leap, raindrops, reverse-string, two-fer

This commit is contained in:
Xevion
2021-11-26 02:28:45 -06:00
parent e02f2ceabf
commit 3bd08f4c92
29 changed files with 569 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
{
"blurb": "Given a year, report if it is a leap year.",
"authors": [
"spuder"
],
"contributors": [
"gyssels",
"kchenery"
],
"files": {
"solution": [
"LeapYear.ps1"
],
"test": [
"LeapYear.tests.ps1"
],
"example": [
".meta/LeapYear.example.ps1"
]
},
"source": "JavaRanch Cattle Drive, exercise 3",
"source_url": "http://www.javaranch.com/leap.jsp"
}

View File

@@ -0,0 +1 @@
{"track":"powershell","exercise":"leap","id":"0a3fd49cec7f4abab206a09b5accdf20","url":"https://exercism.org/tracks/powershell/exercises/leap","handle":"Xevion","is_requester":true,"auto_approve":false}

1
powershell/leap/.version Normal file
View File

@@ -0,0 +1 @@
1

33
powershell/leap/HELP.md Normal file
View 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 LeapYear.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/

View File

@@ -0,0 +1,9 @@
function Test-LeapYear {
param( [int]$year )
if ((($year % 4 -eq 0) -and !($year % 100 -eq 0)) -or ($year % 400 -eq 0)) {
return $true
}
return $false
}

View File

@@ -0,0 +1,21 @@
BeforeAll {
. ".\LeapYear.ps1"
}
Describe "LeapYear Tests" {
It "Year not divisible by 4: common year" {
Test-LeapYear(2015) | Should -Be $false
}
It "Year divisible by 4, not divisible by 100: leap year" {
Test-LeapYear(1996) | Should -Be $true
}
It "Year divisible by 100, not divisible by 400: common year" {
Test-LeapYear(2100) | Should -Be $false
}
It "Year divisible by 400: leap year" {
Test-LeapYear(2000) | Should -Be $true
}
}

44
powershell/leap/README.md Normal file
View File

@@ -0,0 +1,44 @@
# Leap
Welcome to Leap on Exercism's PowerShell Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Given a year, report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
```text
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
unless the year is also evenly divisible by 400
```
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
year, but 2000 is.
## Notes
Though our exercise adopts some very simple rules, there is more to
learn!
For a delightful, four minute explanation of the whole leap year
phenomenon, go watch [this youtube video][video].
[video]: http://www.youtube.com/watch?v=xX96xng7sAE
## Source
### Created by
- @spuder
### Contributed to by
- @gyssels
- @kchenery
### Based on
JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp