forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsolar_system_test.rb
79 lines (61 loc) · 2.86 KB
/
solar_system_test.rb
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/skip_dsl'
require_relative '../lib/solar_system.rb'
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
describe 'Solar System' do
describe 'initialize solar system' do
it 'creates an instance of Solar System' do
star_name = 'Sun'
solar_system = SolarSystem.new(star_name)
expect(solar_system).must_be_instance_of SolarSystem
end
end
end
describe 'add planet' do
it 'adds a planet' do
solar_system = SolarSystem.new("Sun")
earth = Planet.new('Earth','blue-green',5.972e24,1.496e8,"it is the only planet known to support life.")
mars = Planet.new("Mars", "red", 6.39e23, 2.066e8, "it has the highest mountain in our solar system (24km).")
solar_system.add_planet(earth)
solar_system.add_planet(mars)
expect(solar_system.planets.length).must_equal 2
end
end
describe 'list planet' do
it 'lists the planets' do
solar_system = SolarSystem.new('Sun')
expect(solar_system.list_planets).must_be_instance_of String
earth = Planet.new('Earth','blue-green',5.972e24,1.496e8,"it is the only planet known to support life.")
mars = Planet.new("Mars", "red", 6.39e23, 2.066e8, "it has the highest mountain in our solar system (24km).")
solar_system.add_planet(earth)
solar_system.add_planet(mars)
expect(solar_system.list_planets).must_equal "Planets orbiting the Sun \n1. Earth \n2. Mars \n"
end
end
describe 'finds a planet by name' do
it 'raises an error if the planet cannot be found' do
solar_system = SolarSystem.new("Sun")
earth = Planet.new('Earth','blue-green',5.972e24,1.496e8,"it is the only planet known to support life.")
mars = Planet.new("Mars","red",6.39e23,2.066e8,"it has the highest mountain in our solar system (24km).")
solar_system.add_planet(earth)
solar_system.add_planet(mars)
expect{solar_system.find_planet_by_name("Mercury")}.must_raise ArgumentError
end
it 'if the planet can be found it must be an instance of the class Planet' do
solar_system = SolarSystem.new("Sun")
earth = Planet.new('Earth','blue-green',5.972e24,1.496e8,"it is the only planet known to support life.")
solar_system.add_planet(earth)
expect(solar_system.find_planet_by_name("Earth")).must_be_instance_of Planet
end
end
describe 'distance between' do
it 'calculates the distance between two planets' do
solar_system = SolarSystem.new("Sun")
earth = Planet.new("Earth",'blue-green',5.972e24,1.496e8,"it is the only planet known to support life.")
mars = Planet.new("Mars","red",6.39e23,2.066e8,"it has the highest mountain in our solar system (24km).")
solar_system.add_planet(earth)
solar_system.add_planet(mars)
expect(solar_system.distance_between("Earth", "Mars")).must_be_close_to 57000000
end
end