forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Ports - Laneia #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
laneia
wants to merge
11
commits into
Ada-C11:master
Choose a base branch
from
laneia:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ports - Laneia #43
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
83d5bbb
Initial work waves 1-3
1966f47
Added optional enhancements.
11b781e
Moved 3 files to lib, added spec for planet
1141af5
Continued spec work. Tried to get distance method to work with new p…
7710c9a
Fixed call method
ff9557d
minor adjustments
4e1a32f
got distance between added planet and other planets working. GET IT.
c02ce3a
Delete planet.rb
laneia db820c8
Delete solar_system.rb
laneia aff4cab
Delete planet_spec.rb
laneia 0a924c6
Delete main.rb
laneia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| require_relative "planet" | ||
| require_relative "solar_system" | ||
|
|
||
| def main | ||
| solar_system = SolarSystem.new("Sol") | ||
|
|
||
| mercury = Planet.new("Mercury", "grey", 0.33e24, 57.9e6, "it has ice in craters that never receive sunlight.") | ||
| solar_system.add_planet(mercury) | ||
|
|
||
| venus = Planet.new("Venus", "yellow", 4.87e24, 108.2e6, "it probably had a moon, but collided with it after another impact reversed the planet's spin.") | ||
| solar_system.add_planet(venus) | ||
|
|
||
| earth = Planet.new("Earth", "blue", 5.97e24, 149.6e6, "it has more life than the rest of the known universe, as far as we know.") | ||
| solar_system.add_planet(earth) | ||
|
|
||
| mars = Planet.new("Mars", "red", 0.64e24, 227.9e6, "it has liquid water.") | ||
| solar_system.add_planet(mars) | ||
|
|
||
| jupiter = Planet.new("Jupiter", "orange", 1898e24, 778.3e6, "its gravity breaks apart many comets.") | ||
| solar_system.add_planet(jupiter) | ||
|
|
||
| saturn = Planet.new("Saturn", "gold", 569e24, 1427e6, "it's not known how or when its rings formed.") | ||
| solar_system.add_planet(saturn) | ||
|
|
||
| uranus = Planet.new("Uranus", "blue", 86.8e24, 2871e6, "it also has large storms in its atmosphere, like Jupiter.") | ||
| solar_system.add_planet(uranus) | ||
|
|
||
| neptune = Planet.new("Neptune", "blue", 102e24, 5913e6, "the wind can go as fast as 1,700 km/hr - faster than the speed of sound.") | ||
| solar_system.add_planet(neptune) | ||
|
|
||
| continue = true | ||
|
|
||
| while continue == true | ||
| puts "What would you like to do next?" | ||
| puts "list planets | planet details | add planet | distance between planets | exit" | ||
| get_input = gets.chomp | ||
| if get_input == "exit" | ||
| puts "See ya!" | ||
| return continue == false | ||
| elsif get_input == "list planets" | ||
| puts solar_system.list_planets | ||
| elsif get_input == "planet details" | ||
| puts "Which planet would you like to learn about?" | ||
| input_name = gets.chomp | ||
| puts solar_system.find_planet_by_name(input_name) | ||
| elsif get_input == "add planet" | ||
| solar_system.add_new_planet | ||
| puts "Planet added to the solar system!" | ||
| elsif get_input == "distance between planets" | ||
| puts "What's the first planet you're interested in?" | ||
| planet1_name = gets.chomp | ||
| puts "Sweet, what's the second planet?" | ||
| planet2_name = gets.chomp | ||
| puts solar_system.distance_between(planet1_name, planet2_name) | ||
| else | ||
| puts "Invalid prompt." | ||
| end | ||
| end | ||
| end | ||
|
|
||
| puts "Welcome to the solar system!" | ||
| main | ||
|
|
||
| # Moved to solar_system.rb for now | ||
|
|
||
| # def add_new_planet | ||
| # puts "Okay, what's the name of the planet we're missing?" | ||
| # name = gets.chomp | ||
| # puts "Cool, what color is it?" | ||
| # color = gets.chomp | ||
| # puts "What about its mass in kilograms?" | ||
| # mass_kg = gets.chomp | ||
| # until mass_kg.to_f > 0 | ||
| # puts "Must be a number greater than zero." | ||
| # mass_kg = gets.chomp | ||
| # end | ||
| # puts "Now I need its distance from the sun in kilometers." | ||
| # distance_from_sun_km = gets.chomp | ||
| # until distance_from_sun_km.to_f > 0 | ||
| # puts "Must be a number greater than zero." | ||
| # distance_from_sun_km = gets.chomp | ||
| # end | ||
| # puts "And finally, what's a fun fact about this planet?" | ||
| # fun_fact = gets.chomp | ||
|
|
||
| # return new_planet = Planet.new(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
| # end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Planet | ||
| attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact | ||
|
|
||
| def initialize(name, color, mass_kg, distance_from_sun_km, fun_fact) | ||
| @name = name | ||
| @color = color | ||
| @mass_kg = mass_kg | ||
| @distance_from_sun_km = distance_from_sun_km | ||
| @fun_fact = fun_fact | ||
| end | ||
|
|
||
| def summary | ||
| return "#{@name} is a #{@color} planet that weighs #{mass_kg} kilograms and orbits #{@distance_from_sun_km} kilometers from the sun. A cool fact about #{@name} is that #{fun_fact}" | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| require_relative "planet" | ||
|
|
||
| class SolarSystem | ||
| attr_reader :star_name, :planets | ||
|
|
||
| def initialize(star_name) | ||
| @star_name = star_name | ||
| @planets = [] | ||
| @planet_print = ["Planets orbiting #{star_name}"] | ||
| #@new_planet | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| @planets << planet | ||
| end | ||
|
|
||
| def add_new_planet | ||
| print "Okay, what's the name of the planet we're missing?\n" | ||
| new_name = gets.chomp | ||
| print "Cool, what color is it?\n" | ||
| new_color = gets.chomp | ||
| print "What about its mass in kilograms?\n" | ||
| new_mass_kg = gets.chomp.to_f | ||
| until new_mass_kg > 0 | ||
| print "Must be a number greater than zero.\n" | ||
| new_mass_kg = gets.chomp.to_f | ||
| end | ||
| print "Now I need its distance from the sun in kilometers.\n" | ||
| new_distance = gets.chomp.to_f | ||
| until new_distance > 0 | ||
| print "Must be a number greater than zero.\n" | ||
| new_distance = gets.chomp.to_f | ||
| end | ||
| print "And finally, what's a fun fact about this planet?\n" | ||
| new_fun_fact = gets.chomp | ||
|
|
||
| new_planet = Planet.new(new_name, new_color, new_mass_kg, new_distance, new_fun_fact) | ||
| add_planet(new_planet) | ||
| end | ||
|
|
||
| def list_planets | ||
| @planets.each_index do |index| | ||
| @planet_print << "#{index + 1}. #{@planets[index].name}" | ||
| end | ||
| return @planet_print | ||
| end | ||
|
|
||
| def find_planet_by_name(input_name) | ||
| @planets.each do |each_planet| | ||
| if each_planet.name.casecmp(input_name) == 0 | ||
| return each_planet.summary | ||
| end | ||
| end | ||
| return "Invalid planet." | ||
| end | ||
|
|
||
| def find_planet_distance_by_name(planet) | ||
| @planets.each do |each_planet| | ||
| if each_planet.name.casecmp(planet) == 0 | ||
| return each_planet.distance_from_sun_km | ||
| end | ||
| end | ||
| return "Invalid planet." | ||
| end | ||
|
|
||
| def distance_between(planet1_name, planet2_name) | ||
| planet1_position = find_planet_distance_by_name(planet1_name) | ||
| planet2_position = find_planet_distance_by_name(planet2_name) | ||
| if planet1_position.is_a?(Float) == false || planet2_position.is_a?(Float) == false | ||
| return "Invalid planet entered." | ||
| end | ||
| return "#{(planet2_position - planet1_position).abs} kilometers" | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| gem "minitest", ">= 5.0.0" | ||
| require "minitest" | ||
| require "minitest/spec" | ||
| require "minitest/autorun" | ||
| require "minitest/reporters" | ||
| require "minitest/pride" | ||
|
|
||
| require_relative "../lib/planet" | ||
|
|
||
| describe "Planets tests" do | ||
| it "Tests mass is greater than zero" do | ||
| mercury = Planet.new("Mercury", "grey", 0.33e24, 57.9e6, "it has ice in craters that never receive sunlight.") | ||
| expect(mercury.mass_kg).must_be :>, 0 | ||
| end | ||
|
|
||
| it "Tests distance is greater than zero" do | ||
| mercury = Planet.new("Mercury", "grey", 0.33e24, 57.9e6, "it has ice in craters that never receive sunlight.") | ||
| expect(mercury.distance_from_sun_km).must_be :>, 0 | ||
| end | ||
|
|
||
| it "Test planet variable assignment and summary" do | ||
| mercury = Planet.new("Mercury", "grey", 0.33e24, 57.9e6, "it has ice in craters that never receive sunlight.") | ||
| expect(mercury.summary).must_equal "Mercury is a grey planet that weighs 3.3e+23 kilograms and orbits 57900000.0 kilometers from the sun. A cool fact about Mercury is that it has ice in craters that never receive sunlight." | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| gem "minitest", ">= 5.0.0" | ||
| require "minitest" | ||
| require "minitest/spec" | ||
| require "minitest/autorun" | ||
| require "minitest/reporters" | ||
| require "minitest/pride" | ||
|
|
||
| # require_relative "../lib/planet" | ||
| require_relative "../lib/solar_system" | ||
|
|
||
| describe "Solar system tests" do | ||
| it "Tests planet finding" do | ||
| solar_system = SolarSystem.new("Sol") | ||
| @planets = ["earth", "mars"] | ||
| expect(solar_system.find_planet_by_name("mars2")).must_match "Invalid planet." | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be moved to
main.rbThat way you would separate the user interface role with the job of keeping and tracking the list of planets.