-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_planet.py
58 lines (46 loc) · 1.88 KB
/
test_planet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import unittest
from planet import Planet
class TestPlanet(unittest.TestCase):
def setUp(self):
self.earth = Planet(
name="Earth", mass=5.97e24, distance_from_sun=150000000.0, moons=["Moon"]
)
self.mars = Planet(
name="Mars",
mass=6.41e23,
distance_from_sun=230000000.0,
moons=["Phobos", "Deimos"],
)
self.mercury = Planet(
name="Mercury", mass=3.30e23, distance_from_sun=70000000, moons=[]
)
def test_init(self):
self.assertEqual(self.earth.name, "Earth")
self.assertEqual(self.earth.mass, 5.97e24)
self.assertEqual(self.earth.distance_from_sun, 150000000)
self.assertEqual(self.earth.moons, ["Moon"])
def test_str(self):
expected_output = (
"Name: Earth\n"
"Mass: 5.97e+24 kg\n"
"Distance from Sun: 150000000.0 km\n"
"Moons: Moon"
)
self.assertEqual(str(self.earth), expected_output)
def test_get_mass(self):
expected_output = "Earth has a mass of 5.97e+24 kg."
self.assertEqual(self.earth.get_mass(), expected_output)
def test_get_distance_from_sun(self):
expected_output = "Earth is 150000000.0 km from the sun."
self.assertEqual(self.earth.get_distance_from_sun(), expected_output)
def test_get_moon_count_single(self):
expected_output = "Earth has 1 moon: Moon"
self.assertEqual(self.earth.get_moon_count(), expected_output)
def test_get_moon_count_multiple(self):
expected_output = "Mars has 2 moons: Phobos, Deimos"
self.assertEqual(self.mars.get_moon_count(), expected_output)
def test_get_moon_count_none(self):
expected_output = "Mercury has 0 moons"
self.assertEqual(self.mercury.get_moon_count(), expected_output)
if __name__ == "__main__":
unittest.main()