diff --git a/exercises/practice/space-age/.meta/src/reference/java/SpaceAge.java b/exercises/practice/space-age/.meta/src/reference/java/SpaceAge.java index 6143ed0b5..67e1bbaf1 100644 --- a/exercises/practice/space-age/.meta/src/reference/java/SpaceAge.java +++ b/exercises/practice/space-age/.meta/src/reference/java/SpaceAge.java @@ -1,5 +1,3 @@ -import java.math.BigDecimal; - class SpaceAge { private enum Planet { @@ -24,8 +22,6 @@ private double getRelativeOrbitalPeriod() { } private static final double EARTH_ORBITAL_PERIOD_IN_SECONDS = 31557600.0; - private static final int PRECISION = 2; - private double seconds; SpaceAge(double seconds) { @@ -65,9 +61,7 @@ private double getRelativeOrbitalPeriod() { } private double calculateAge(Planet planet) { - double age = seconds / (EARTH_ORBITAL_PERIOD_IN_SECONDS * planet.getRelativeOrbitalPeriod()); - - return new BigDecimal(age).setScale(PRECISION, BigDecimal.ROUND_HALF_UP).doubleValue(); + return (seconds / EARTH_ORBITAL_PERIOD_IN_SECONDS) / planet.getRelativeOrbitalPeriod(); } } diff --git a/exercises/practice/space-age/.meta/tests.toml b/exercises/practice/space-age/.meta/tests.toml index b4a221dc9..4b65f23af 100644 --- a/exercises/practice/space-age/.meta/tests.toml +++ b/exercises/practice/space-age/.meta/tests.toml @@ -1,6 +1,13 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. [84f609af-5a91-4d68-90a3-9e32d8a5cd34] description = "age on Earth" @@ -25,3 +32,8 @@ description = "age on Uranus" [80096d30-a0d4-4449-903e-a381178355d8] description = "age on Neptune" + +[57b96e2a-1178-40b7-b34d-f3c9c34e4bf4] +description = "invalid planet causes error" +include = false +comment = "Excluded because the design of the exercise does not allow for arbitrary planets" diff --git a/exercises/practice/space-age/src/test/java/SpaceAgeTest.java b/exercises/practice/space-age/src/test/java/SpaceAgeTest.java index 72a551dc4..fdf5172d8 100644 --- a/exercises/practice/space-age/src/test/java/SpaceAgeTest.java +++ b/exercises/practice/space-age/src/test/java/SpaceAgeTest.java @@ -2,7 +2,7 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.within; +import static org.assertj.core.api.Assertions.offset; public class SpaceAgeTest { @@ -12,7 +12,7 @@ public class SpaceAgeTest { public void ageOnEarth() { SpaceAge age = new SpaceAge(1000000000); - assertThat(age.onEarth()).isEqualTo(31.69, within(MAXIMUM_DELTA)); + assertThat(age.onEarth()).isEqualTo(31.69, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -20,7 +20,7 @@ public void ageOnEarth() { public void ageOnMercury() { SpaceAge age = new SpaceAge(2134835688); - assertThat(age.onMercury()).isEqualTo(280.88, within(MAXIMUM_DELTA)); + assertThat(age.onMercury()).isEqualTo(280.88, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -28,7 +28,7 @@ public void ageOnMercury() { public void ageOnVenus() { SpaceAge age = new SpaceAge(189839836); - assertThat(age.onVenus()).isEqualTo(9.78, within(MAXIMUM_DELTA)); + assertThat(age.onVenus()).isEqualTo(9.78, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -36,7 +36,7 @@ public void ageOnVenus() { public void ageOnMars() { SpaceAge age = new SpaceAge(2129871239L); - assertThat(age.onMars()).isEqualTo(35.88, within(MAXIMUM_DELTA)); + assertThat(age.onMars()).isEqualTo(35.88, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -44,7 +44,7 @@ public void ageOnMars() { public void ageOnJupiter() { SpaceAge age = new SpaceAge(901876382); - assertThat(age.onJupiter()).isEqualTo(2.41, within(MAXIMUM_DELTA)); + assertThat(age.onJupiter()).isEqualTo(2.41, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -52,7 +52,7 @@ public void ageOnJupiter() { public void ageOnSaturn() { SpaceAge age = new SpaceAge(2000000000L); - assertThat(age.onSaturn()).isEqualTo(2.15, within(MAXIMUM_DELTA)); + assertThat(age.onSaturn()).isEqualTo(2.15, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -60,7 +60,7 @@ public void ageOnSaturn() { public void ageOnUranus() { SpaceAge age = new SpaceAge(1210123456L); - assertThat(age.onUranus()).isEqualTo(0.46, within(MAXIMUM_DELTA)); + assertThat(age.onUranus()).isEqualTo(0.46, offset(MAXIMUM_DELTA)); } @Ignore("Remove to run test") @@ -68,6 +68,6 @@ public void ageOnUranus() { public void ageOnNeptune() { SpaceAge age = new SpaceAge(1821023456L); - assertThat(age.onNeptune()).isEqualTo(0.35, within(MAXIMUM_DELTA)); + assertThat(age.onNeptune()).isEqualTo(0.35, offset(MAXIMUM_DELTA)); } }