diff --git a/config.json b/config.json index ae0186ec6..9360cbfff 100644 --- a/config.json +++ b/config.json @@ -11,6 +11,7 @@ "allergies", "word-count", "hamming", + "gigasecond", "rna-transcription", "nucleotide-count", "nucleotide-codons", diff --git a/exercises/gigasecond/Cargo.lock b/exercises/gigasecond/Cargo.lock new file mode 100644 index 000000000..082c59411 --- /dev/null +++ b/exercises/gigasecond/Cargo.lock @@ -0,0 +1,55 @@ +[root] +name = "gigasecond" +version = "0.0.0" +dependencies = [ + "chrono 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "chrono" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "time" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + diff --git a/exercises/gigasecond/Cargo.toml b/exercises/gigasecond/Cargo.toml new file mode 100644 index 000000000..6d27d9c68 --- /dev/null +++ b/exercises/gigasecond/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "gigasecond" +version = "0.0.0" + +[dependencies] +chrono = "0.2" + diff --git a/exercises/gigasecond/example.rs b/exercises/gigasecond/example.rs new file mode 100644 index 000000000..b85756ffb --- /dev/null +++ b/exercises/gigasecond/example.rs @@ -0,0 +1,6 @@ +extern crate chrono; +use chrono::*; + +pub fn after(start: DateTime) -> DateTime { + start + Duration::seconds(1_000_000_000) +} diff --git a/exercises/gigasecond/tests/gigasecond.rs b/exercises/gigasecond/tests/gigasecond.rs new file mode 100644 index 000000000..92ebd1125 --- /dev/null +++ b/exercises/gigasecond/tests/gigasecond.rs @@ -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)); +}