fortitude

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 """
19 Initialize the SpaceAge object with an age in seconds.
20
21 Args:
22 seconds (int): Age in seconds
23
24 Edge Case: Negative seconds - While not physically meaningful, the calculation will proceed
25 Edge Case: Zero seconds - Results in age 0.0 on all planets
26 """
27 # Edge Case: Non-integer input - Convert to integer if possible, otherwise raise TypeError
28 if not isinstance(seconds, (int, float)):
29 raise TypeError("Seconds must be a number")
30
31 self.seconds = int(seconds)
32
33 def _calculate_age_on_planet(self, planet: str) -> float:
34 """
35 Calculate age on a specific planet.
36
37 Args:
38 planet (str): Name of the planet
39
40 Returns:
41 float: Age on the planet rounded to 2 decimal places
42 """
43 # Edge Case: Division by zero - Prevented by ensuring Earth year constant is non-zero
44 earth_years = self.seconds / self.EARTH_YEAR_SECONDS
45 planet_years = earth_years / self.ORBITAL_PERIODS[planet]
46 return round(planet_years, 2)
47
48 def on_mercury(self) -> float:
49 """
50 Calculate age on Mercury.
51
52 Returns:
53 float: Age on Mercury in years, rounded to 2 decimal places
54 """
55 return self._calculate_age_on_planet('mercury')
56
57 def on_venus(self) -> float:
58 """
59 Calculate age on Venus.
60
61 Returns:
62 float: Age on Venus in years, rounded to 2 decimal places
63 """
64 return self._calculate_age_on_planet('venus')
65
66 def on_earth(self) -> float:
67 """
68 Calculate age on Earth.
69
70 Returns:
71 float: Age on Earth in years, rounded to 2 decimal places
72 """
73 return self._calculate_age_on_planet('earth')
74
75 def on_mars(self) -> float:
76 """
77 Calculate age on Mars.
78
79 Returns:
80 float: Age on Mars in years, rounded to 2 decimal places
81 """
82 return self._calculate_age_on_planet('mars')
83
84 def on_jupiter(self) -> float:
85 """
86 Calculate age on Jupiter.
87
88 Returns:
89 float: Age on Jupiter in years, rounded to 2 decimal places
90 """
91 return self._calculate_age_on_planet('jupiter')
92
93 def on_saturn(self) -> float:
94 """
95 Calculate age on Saturn.
96
97 Returns:
98 float: Age on Saturn in years, rounded to 2 decimal places
99 """
100 return self._calculate_age_on_planet('saturn')
101
102 def on_uranus(self) -> float:
103 """
104 Calculate age on Uranus.
105
106 Returns:
107 float: Age on Uranus in years, rounded to 2 decimal places
108 """
109 return self._calculate_age_on_planet('uranus')
110
111 def on_neptune(self) -> float:
112 """
113 Calculate age on Neptune.
114
115 Returns:
116 float: Age on Neptune in years, rounded to 2 decimal places
117 """
118 return self._calculate_age_on_planet('neptune')
119
120# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input, Division by zero
121# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
122# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
123# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
124# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
125# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
126# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer input
127# Handled Edge Cases: Negative seconds, Zero seconds, Non-integer 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.