Skip to content

Implement Gigasecond exercise #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"allergies",
"word-count",
"hamming",
"gigasecond",
"rna-transcription",
"nucleotide-count",
"nucleotide-codons",
Expand Down
55 changes: 55 additions & 0 deletions exercises/gigasecond/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions exercises/gigasecond/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "gigasecond"
version = "0.0.0"

[dependencies]
chrono = "0.2"

6 changes: 6 additions & 0 deletions exercises/gigasecond/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern crate chrono;
use chrono::*;

pub fn after(start: DateTime<UTC>) -> DateTime<UTC> {
start + Duration::seconds(1_000_000_000)
}
50 changes: 50 additions & 0 deletions exercises/gigasecond/tests/gigasecond.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
extern crate gigasecond;

/*
* Students,
*
* Rust does not currently have a library for handling Time. To solve this exercise
* you'll need to use the Chrono 'crate' (which is Rust's term for an external library).
*
* The first time you run `cargo test`, the Chrono crate will automatically be downloaded
* and installed. More information on crates can be found at
* https://doc.rust-lang.org/book/guessing-game.html#generating-a-secret-number
*
* In order to use the crate, your solution will need to start with the two following lines
*/
extern crate chrono;
use chrono::*;

#[test]
fn test_date() {
let start_date = UTC.ymd(2011, 4, 25).and_hms(0,0,0);
assert_eq!(gigasecond::after(start_date), UTC.ymd(2043, 1, 1).and_hms(1,46,40));
}

#[test]
#[ignore]
fn test_another_date() {
let start_date = UTC.ymd(1977, 6, 13).and_hms(0,0,0);
assert_eq!(gigasecond::after(start_date), UTC.ymd(2009, 2, 19).and_hms(1,46,40));
}

#[test]
#[ignore]
fn test_third_date() {
let start_date = UTC.ymd(1959, 7, 19).and_hms(0,0,0);
assert_eq!(gigasecond::after(start_date), UTC.ymd(1991, 3, 27).and_hms(1,46,40));
}

#[test]
#[ignore]
fn test_datetime() {
let start_date = UTC.ymd(2015, 1, 24).and_hms(22,0,0);
assert_eq!(gigasecond::after(start_date), UTC.ymd(2046, 10, 2).and_hms(23,46,40));
}

#[test]
#[ignore]
fn test_another_datetime() {
let start_date = UTC.ymd(2015, 1, 24).and_hms(23,59,59);
assert_eq!(gigasecond::after(start_date), UTC.ymd(2046, 10, 3).and_hms(1,46,39));
}