Browse Source

Gigasecond

master
Julio Biason 12 months ago
parent
commit
1c43af6a8f
  1. 27
      groovy/gigasecond/.exercism/config.json
  2. 1
      groovy/gigasecond/.exercism/metadata.json
  3. 48
      groovy/gigasecond/HELP.md
  4. 55
      groovy/gigasecond/README.md
  5. 18
      groovy/gigasecond/build.gradle
  6. 16
      groovy/gigasecond/src/main/groovy/Gigasecond.groovy
  7. 54
      groovy/gigasecond/src/test/groovy/GigasecondSpec.groovy

27
groovy/gigasecond/.exercism/config.json

@ -0,0 +1,27 @@
{
"authors": [],
"contributors": [
"alexanderific",
"amscotti",
"baincd",
"Dispader",
"ikhadykin",
"kytrinyx",
"Raibaz",
"sjwarner-bp"
],
"files": {
"solution": [
"src/main/groovy/Gigasecond.groovy"
],
"test": [
"src/test/groovy/GigasecondSpec.groovy"
],
"example": [
".meta/src/reference/groovy/Gigasecond.groovy"
]
},
"blurb": "Given a moment, determine the moment that would be after a gigasecond has passed.",
"source": "Chapter 9 in Chris Pine's online Learn to Program tutorial.",
"source_url": "https://pine.fm/LearnToProgram/?Chapter=09"
}

1
groovy/gigasecond/.exercism/metadata.json

@ -0,0 +1 @@
{"track":"groovy","exercise":"gigasecond","id":"bd17c521d76e408ea531477b04f0fc1b","url":"https://exercism.org/tracks/groovy/exercises/gigasecond","handle":"JBiason","is_requester":true,"auto_approve":false}

48
groovy/gigasecond/HELP.md

@ -0,0 +1,48 @@
# Help
## Running the tests
On MacOS/Linux, please run:
```sh
$ chmod +x gradlew
```
Execute the tests with:
```sh
$ ./gradlew test
```
> Use `gradlew.bat` if you're on Windows
## Skipped tests
After the first test(s) pass, continue by commenting out or removing the `@Ignore` annotations prepending other tests.
## Submitting your solution
You can submit your solution using the `exercism submit src/main/groovy/Gigasecond.groovy` 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 [Groovy track's documentation](https://exercism.org/docs/tracks/groovy)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- 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're having trouble, you can use one of the following resources:
- The [Groovy Language Documentation](http://docs.groovy-lang.org/docs/latest/html/documentation/)
- The [Groovy Community](http://www.groovy-lang.org/community.html) entry of the Groovy Language Documentation
- [/r/groovy](https://www.reddit.com/r/groovy) is the Groovy subreddit.
- [StackOverflow](http://stackoverflow.com/questions/tagged/groovy) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

55
groovy/gigasecond/README.md

@ -0,0 +1,55 @@
# Gigasecond
Welcome to Gigasecond on Exercism's Groovy Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Introduction
The way we measure time is kind of messy.
We have 60 seconds in a minute, and 60 minutes in an hour.
This comes from ancient Babylon, where they used 60 as the basis for their number system.
We have 24 hours in a day, 7 days in a week, and how many days in a month?
Well, for days in a month it depends not only on which month it is, but also on what type of calendar is used in the country you live in.
What if, instead, we only use seconds to express time intervals?
Then we can use metric system prefixes for writing large numbers of seconds in more easily comprehensible quantities.
- A food recipe might explain that you need to let the brownies cook in the oven for two kiloseconds (that's two thousand seconds).
- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.
```exercism/note
If we ever colonize Mars or some other planet, measuring time is going to get even messier.
If someone says "year" do they mean a year on Earth or a year on Mars?
The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge.
In it the author uses the metric system as the basis for time measurements.
[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
```
## Instructions
Your task is to determine the date and time one gigasecond after a certain date.
A gigasecond is one thousand million seconds.
That is a one with nine zeros after it.
If you were born on _January 24th, 2015 at 22:00 (10:00:00pm)_, then you would be a gigasecond old on _October 2nd, 2046 at 23:46:40 (11:46:40pm)_.
## Source
### Contributed to by
- @alexanderific
- @amscotti
- @baincd
- @Dispader
- @ikhadykin
- @kytrinyx
- @Raibaz
- @sjwarner-bp
### Based on
Chapter 9 in Chris Pine's online Learn to Program tutorial. - https://pine.fm/LearnToProgram/?Chapter=09

18
groovy/gigasecond/build.gradle

@ -0,0 +1,18 @@
apply plugin: "groovy"
repositories {
mavenCentral()
}
dependencies {
testImplementation "org.spockframework:spock-core:2.0-M2-groovy-3.0"
implementation "org.codehaus.groovy:groovy-all:3.0.2"
}
test {
useJUnitPlatform()
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
}
}

16
groovy/gigasecond/src/main/groovy/Gigasecond.groovy

@ -0,0 +1,16 @@
import java.time.LocalDateTime
import java.time.LocalDate
class Gigasecond {
static long GIGASECOND = 1_000_000_000
static LocalDateTime add(LocalDate initial) {
add(initial?.atStartOfDay())
}
static LocalDateTime add(LocalDateTime initial) {
initial?.plusSeconds(GIGASECOND)
}
}

54
groovy/gigasecond/src/test/groovy/GigasecondSpec.groovy

@ -0,0 +1,54 @@
import spock.lang.*
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.Month
class GigasecondSpec extends Specification {
def "Date only specification of time"() {
expect:
Gigasecond.add(moment) == expected
where:
moment = LocalDate.of(2011, Month.APRIL, 25)
expected = LocalDateTime.of(2043, Month.JANUARY, 1, 1, 46, 40)
}
def "Second test for date only specification of time"() {
expect:
Gigasecond.add(moment) == expected
where:
moment = LocalDate.of(1977, Month.JUNE, 13)
expected = LocalDateTime.of(2009, Month.FEBRUARY, 19, 1, 46, 40)
}
def "Third test for date only specification of time"() {
expect:
Gigasecond.add(moment) == expected
where:
moment = LocalDate.of(1959, Month.JULY, 19)
expected = LocalDateTime.of(1991, Month.MARCH, 27, 1, 46, 40)
}
def "Full time specified"() {
expect:
Gigasecond.add(moment) == expected
where:
moment = LocalDateTime.of(2015, Month.JANUARY, 24, 22, 0, 0)
expected = LocalDateTime.of(2046, Month.OCTOBER, 2, 23, 46, 40)
}
def "Full time with day roll-over"() {
expect:
Gigasecond.add(moment) == expected
where:
moment = LocalDateTime.of(2015, Month.JANUARY, 24, 23, 59, 59)
expected = LocalDateTime.of(2046, Month.OCTOBER, 3, 1, 46, 39)
}
}
Loading…
Cancel
Save