diff options
author | Andinus <andinus@nand.sh> | 2021-09-29 20:18:42 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-09-29 20:18:42 +0530 |
commit | 6cb0e630baeb9a5acddac65a627bd2f9bf291312 (patch) | |
tree | 9a95f52c2570b063a7cc40d30b883cbacc812b37 /rust/space-age/tests | |
parent | b7f76db2a02aba793a68ba35c2b4b51d5e069bdc (diff) | |
download | exercism-6cb0e630baeb9a5acddac65a627bd2f9bf291312.tar.gz |
Rust: Space Age: Add exercise
Diffstat (limited to 'rust/space-age/tests')
-rw-r--r-- | rust/space-age/tests/space-age.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/rust/space-age/tests/space-age.rs b/rust/space-age/tests/space-age.rs new file mode 100644 index 0000000..b54e2f4 --- /dev/null +++ b/rust/space-age/tests/space-age.rs @@ -0,0 +1,67 @@ +use space_age::*; + +fn assert_in_delta(expected: f64, actual: f64) { + let diff: f64 = (expected - actual).abs(); + let delta: f64 = 0.01; + if diff > delta { + panic!( + "Your result of {} should be within {} of the expected result {}", + actual, delta, expected + ) + } +} + +#[test] +fn earth_age() { + let duration = Duration::from(1_000_000_000); + assert_in_delta(31.69, Earth::years_during(&duration)); +} + +#[test] +#[ignore] +fn mercury_age() { + let duration = Duration::from(2_134_835_688); + assert_in_delta(280.88, Mercury::years_during(&duration)); +} + +#[test] +#[ignore] +fn venus_age() { + let duration = Duration::from(189_839_836); + assert_in_delta(9.78, Venus::years_during(&duration)); +} + +#[test] +#[ignore] +fn mars_age() { + let duration = Duration::from(2_129_871_239); + assert_in_delta(35.88, Mars::years_during(&duration)); +} + +#[test] +#[ignore] +fn jupiter_age() { + let duration = Duration::from(901_876_382); + assert_in_delta(2.41, Jupiter::years_during(&duration)); +} + +#[test] +#[ignore] +fn saturn_age() { + let duration = Duration::from(2_000_000_000); + assert_in_delta(2.15, Saturn::years_during(&duration)); +} + +#[test] +#[ignore] +fn uranus_age() { + let duration = Duration::from(1_210_123_456); + assert_in_delta(0.46, Uranus::years_during(&duration)); +} + +#[test] +#[ignore] +fn neptune_age() { + let duration = Duration::from(1_821_023_456); + assert_in_delta(0.35, Neptune::years_during(&duration)); +} |