kale

Finished
11class SpaceAge:
2 # Earth year in seconds
3 EARTH_YEAR_SECONDS = 31557600
4
5 # Orbital periods in Earth years
6 ORBITAL_PERIODS = {
7 'mercury': 0.2408467,
8 'venus': 0.61519726,
9 'earth': 1.0,
10 'mars': 1.8808158,
11 'jupiter': 11.862615,
12 'saturn': 29.447498,
13 'uranus': 84.016846,
14 'neptune': 164.79132
15 }
16
217 def __init__(self, seconds: int) -> None:
3 pass
18 # Edge Case: Handle negative seconds input
19 if seconds < 0:
20 raise ValueError("Seconds cannot be negative")
21
22 # Edge Case: Handle non-integer input by converting to int
23 self.seconds = int(seconds)
24
25 # Edge Case: Handle very large numbers by ensuring they're within reasonable bounds
26 # (Python can handle arbitrarily large integers, but we ensure it's a valid number)
27 if not isinstance(seconds, (int, float)):
28 raise TypeError("Seconds must be a number")
29
30 def _calculate_age_on_planet(self, planet_name: str) -> float:
31 """Helper method to calculate age on a specific planet"""
32 orbital_period = self.ORBITAL_PERIODS[planet_name]
33 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
34 planet_years = earth_years / orbital_period
35 return round(planet_years, 2)
36
37 def on_mercury(self) -> float:
38 return self._calculate_age_on_planet('mercury')
39
40 def on_venus(self) -> float:
41 return self._calculate_age_on_planet('venus')
42
43 def on_earth(self) -> float:
44 return self._calculate_age_on_planet('earth')
45
46 def on_mars(self) -> float:
47 return self._calculate_age_on_planet('mars')
48
49 def on_jupiter(self) -> float:
50 return self._calculate_age_on_planet('jupiter')
51
52 def on_saturn(self) -> float:
53 return self._calculate_age_on_planet('saturn')
54
55 def on_uranus(self) -> float:
56 return self._calculate_age_on_planet('uranus')
57
58 def on_neptune(self) -> float:
59 return self._calculate_age_on_planet('neptune')
60
61# Handled Edge Cases: negative seconds input, non-integer input, invalid input types, zero seconds input
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.