corpus

Finished
11class SpaceAge:
2 """
3 A class to calculate the age of a person on different planets in our Solar System.
4
5 The age is calculated based on the number of seconds passed since birth,
6 and converted to planetary years using the orbital periods relative to Earth years.
7
8 Attributes:
9 seconds (int): The age in seconds.
10 """
11
12 # Earth year in seconds
13 EARTH_YEAR_IN_SECONDS = 31557600
14
15 # Orbital periods in Earth years
16 ORBITAL_PERIODS = {
17 'mercury': 0.2408467,
18 'venus': 0.61519726,
19 'earth': 1.0,
20 'mars': 1.8808158,
21 'jupiter': 11.862615,
22 'saturn': 29.447498,
23 'uranus': 84.016846,
24 'neptune': 164.79132
25 }
26
227 def __init__(self, seconds: int) -> None:
3 pass
28 """
29 Initialize the SpaceAge object with the given number of seconds.
30
31 Args:
32 seconds (int): The age in seconds.
33
34 # Handled Edge Cases: None for this method
35 """
36 self.seconds = seconds
37
38 def _calculate_age_on_planet(self, planet: str) -> float:
39 """
40 Calculate the age on a specific planet.
41
42 Args:
43 planet (str): The name of the planet (lowercase).
44
45 Returns:
46 float: The age on the specified planet, rounded to 2 decimal places.
47
48 # Handled Edge Cases: Division by zero (if orbital period was 0),
49 # Invalid planet name (would raise KeyError)
50 """
51 # Edge Case: Invalid planet name - KeyError will be raised if planet not in ORBITAL_PERIODS
52 orbital_period = self.ORBITAL_PERIODS[planet]
53
54 # Edge Case: Division by zero - This would only happen if orbital_period was 0
55 # But since all values are predefined constants, this won't occur
56 earth_years = self.seconds / self.EARTH_YEAR_IN_SECONDS
57 planetary_years = earth_years / orbital_period
58
59 return round(planetary_years, 2)
60
61 def on_mercury(self) -> float:
62 """
63 Calculate the age on Mercury.
64
65 Returns:
66 float: The age on Mercury in years, rounded to 2 decimal places.
67
68 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
69 """
70 return self._calculate_age_on_planet('mercury')
71
72 def on_venus(self) -> float:
73 """
74 Calculate the age on Venus.
75
76 Returns:
77 float: The age on Venus in years, rounded to 2 decimal places.
78
79 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
80 """
81 return self._calculate_age_on_planet('venus')
82
83 def on_earth(self) -> float:
84 """
85 Calculate the age on Earth.
86
87 Returns:
88 float: The age on Earth in years, rounded to 2 decimal places.
89
90 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
91 """
92 return self._calculate_age_on_planet('earth')
93
94 def on_mars(self) -> float:
95 """
96 Calculate the age on Mars.
97
98 Returns:
99 float: The age on Mars in years, rounded to 2 decimal places.
100
101 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
102 """
103 return self._calculate_age_on_planet('mars')
104
105 def on_jupiter(self) -> float:
106 """
107 Calculate the age on Jupiter.
108
109 Returns:
110 float: The age on Jupiter in years, rounded to 2 decimal places.
111
112 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
113 """
114 return self._calculate_age_on_planet('jupiter')
115
116 def on_saturn(self) -> float:
117 """
118 Calculate the age on Saturn.
119
120 Returns:
121 float: The age on Saturn in years, rounded to 2 decimal places.
122
123 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
124 """
125 return self._calculate_age_on_planet('saturn')
126
127 def on_uranus(self) -> float:
128 """
129 Calculate the age on Uranus.
130
131 Returns:
132 float: The age on Uranus in years, rounded to 2 decimal places.
133
134 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
135 """
136 return self._calculate_age_on_planet('uranus')
137
138 def on_neptune(self) -> float:
139 """
140 Calculate the age on Neptune.
141
142 Returns:
143 float: The age on Neptune in years, rounded to 2 decimal places.
144
145 # Handled Edge Cases: None (handled in _calculate_age_on_planet)
146 """
147 return self._calculate_age_on_planet('neptune')
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.