corpus

Finished
11class SpaceAge:
2 """A class to calculate age on different planets based on Earth seconds.
3
4 This class takes an age in seconds and provides methods to calculate
5 the equivalent age on various planets in our solar system.
6
7 Attributes:
8 seconds (int): The age in seconds
9
10 Constants:
11 EARTH_YEAR_IN_SECONDS (int): Number of seconds in an Earth year (31,557,600)
12 """
13
14 # Earth year in seconds
15 EARTH_YEAR_IN_SECONDS = 31557600
16
17 # Orbital periods in Earth years
18 ORBITAL_PERIODS = {
19 'mercury': 0.2408467,
20 'venus': 0.61519726,
21 'earth': 1.0,
22 'mars': 1.8808158,
23 'jupiter': 11.862615,
24 'saturn': 29.447498,
25 'uranus': 84.016846,
26 'neptune': 164.79132
27 }
28
229 def __init__(self, seconds: int) -> None:
3 pass
30 """Initialize the SpaceAge object with seconds.
31
32 Args:
33 seconds (int): Age in seconds
34
35 Edge Case: Negative seconds - While not physically meaningful,
36 the implementation handles negative values by allowing them but
37 producing negative ages.
38 Edge Case: Zero seconds - Handled naturally as zero age on all planets.
39 """
40 # Edge Case: Negative seconds
41 # The implementation allows negative seconds but will produce negative ages
42 # which may not be physically meaningful but mathematically valid
43 self.seconds = seconds
44
45 def _calculate_age_on_planet(self, planet: str) -> float:
46 """Helper method to calculate age on a specific planet.
47
48 Args:
49 planet (str): Name of the planet
50
51 Returns:
52 float: Age on the specified planet, rounded to 2 decimal places
53 """
54 # Calculate Earth years from seconds
55 earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS
56
57 # Calculate age on the specific planet
58 planet_age = earth_years / self.ORBITAL_PERIODS[planet]
59
60 # Round to 2 decimal places
61 return round(planet_age, 2)
62
63 def on_mercury(self) -> float:
64 """Calculate age on Mercury.
65
66 Returns:
67 float: Age on Mercury in Mercury years, rounded to 2 decimal places
68 """
69 return self._calculate_age_on_planet('mercury')
70
71 def on_venus(self) -> float:
72 """Calculate age on Venus.
73
74 Returns:
75 float: Age on Venus in Venus years, rounded to 2 decimal places
76 """
77 return self._calculate_age_on_planet('venus')
78
79 def on_earth(self) -> float:
80 """Calculate age on Earth.
81
82 Returns:
83 float: Age on Earth in Earth years, rounded to 2 decimal places
84
85 Edge Case: Zero seconds - Returns 0.0
86 Edge Case: Negative seconds - Returns negative age
87 """
88 # Edge Case: Zero seconds - Returns 0.0 naturally
89 # Edge Case: Negative seconds - Returns negative age naturally
90 return self._calculate_age_on_planet('earth')
91
92 def on_mars(self) -> float:
93 """Calculate age on Mars.
94
95 Returns:
96 float: Age on Mars in Mars years, rounded to 2 decimal places
97 """
98 return self._calculate_age_on_planet('mars')
99
100 def on_jupiter(self) -> float:
101 """Calculate age on Jupiter.
102
103 Returns:
104 float: Age on Jupiter in Jupiter years, rounded to 2 decimal places
105 """
106 return self._calculate_age_on_planet('jupiter')
107
108 def on_saturn(self) -> float:
109 """Calculate age on Saturn.
110
111 Returns:
112 float: Age on Saturn in Saturn years, rounded to 2 decimal places
113 """
114 return self._calculate_age_on_planet('saturn')
115
116 def on_uranus(self) -> float:
117 """Calculate age on Uranus.
118
119 Returns:
120 float: Age on Uranus in Uranus years, rounded to 2 decimal places
121 """
122 return self._calculate_age_on_planet('uranus')
123
124 def on_neptune(self) -> float:
125 """Calculate age on Neptune.
126
127 Returns:
128 float: Age on Neptune in Neptune years, rounded to 2 decimal places
129 """
130 return self._calculate_age_on_planet('neptune')
131
132 # Handled Edge Cases: Negative seconds, Zero seconds
Test NameStatus
test_age_on_earth
Pass
test_age_on_jupiter
Pass
test_age_on_mars
Pass
test_age_on_mercury
Pass
test_age_on_neptune
Pass
test_age_on_saturn
Pass
test_age_on_uranus
Pass
test_age_on_venus
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.