forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Ports- Sav #30
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
qqdipps
wants to merge
35
commits into
Ada-C11:master
Choose a base branch
from
qqdipps: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- Sav #30
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3d6b471
created new file w/ Planet class.
qqdipps 6f7f64a
added planet constructor
qqdipps d2bbfbe
changed planet param to positional, added main file for main method.
qqdipps 7ef773f
added minitest setup, beg writing tests.
qqdipps e1a5fd9
finished writind first wave of tests.
qqdipps 7cfe570
uncommented constructor, all tests pass.
qqdipps 77f41e7
added summary test of string
qqdipps 8eb900c
fixed typos
qqdipps a59c2a2
added summary method.
qqdipps 703f0f2
adjusted case of planet params.
qqdipps 2fe3046
added method test for summary of planet attributes.
qqdipps 9d4f910
added return summary statements. all tests are up to date and passing.
qqdipps 3d7521c
added tests for edge case for mass and distance == 0.
qqdipps ba9f58e
added error checking for params of distance and mass
qqdipps 8f694fa
added beg tests
qqdipps 52b002f
added SolarSystem class
qqdipps a641b90
added constructor, intial tests pass.
qqdipps 063a527
added add_planet tests and methods. test pass.
qqdipps bb81e72
added require_relative path for solar_system.rb
qqdipps d523f39
added tests and methods for list_planets, add_planets in solar_system.
qqdipps 4dc77be
added solar_system model to main
qqdipps 54b279c
raise exception if not of type Planet when adding planet, added test …
qqdipps a974a7c
added find_planet_by_name methods with tests to confirm. tests pass.
qqdipps 543f8e7
changed variables in main, added find_planet_by_name method in main.
qqdipps 9e6efff
added distance between method and tests, test pass.
qqdipps b6fcf04
added is_a_Planet? method.
qqdipps b077a0f
created layout of main.
qqdipps b9c2ce7
streamed lined main outline
qqdipps 5d1389a
added missing methods, put in module, still working out main structure
qqdipps d34dcab
added main helper methods, and exception handling for CLI
qqdipps 710e344
adding style
qqdipps e5abe55
fixed tests, updated style, added param checking for adding planet if…
qqdipps a111dc4
final txt ascii art added
qqdipps 2b4f52a
added file for art
qqdipps d9fad69
fixed broken file paths
qqdipps 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,9 @@ | ||
| require "rake/testtask" | ||
|
|
||
| Rake::TestTask.new do |t| | ||
| t.libs = ["lib"] | ||
| t.warning = true | ||
| t.test_files = FileList["specs/*_spec.rb"] | ||
| end | ||
|
|
||
| task default: :test |
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,21 @@ | ||
|
|
||
|
|
||
| ________ | ||
| `---. `. | ||
| \ `. | ||
| )_______`. | ||
| .' //`---...___ | ||
| / || // || `-._ | ||
| )`-| =//= || || || / ).`. | ||
| _............_ ).-| || || `........'`-._ (o) | ||
| .-' `.----`. _...'.....__ || || _____ ||-\__.' | ||
| .' | Inter- | ).---.) /_______..--' || || ----- _ ||_/ | ||
| .'_ |Plantery| || || `-------' || || =\\= \_.' | ||
| | | | Travel | |'---'| )`-| || || _..-' | ||
| '--'_____________|_____| ).-| =\\= || \\ _.-' || | ||
| |[]--------------/ / __==\ \\ _.-' /o'\ | ||
| \ .--. / _...--'' '-.__......_.-' \__/ | ||
| `-._//'o\\___.'---'' \ .' | ||
| LGB \__/ -' / / | ||
| ___.' / | ||
| `-------' |
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,9 @@ | ||
|
|
||
|
|
||
| __ | ||
| \ \_____ | ||
| ###[==_____> | ||
| /_/ __ | ||
| \ \_____ | ||
| ###[==_____> | ||
| /_/ |
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,12 @@ | ||
|
|
||
| .::. | ||
| .:' .: | ||
| ,MMM8&&&.:' .:' | ||
| MMMMM88&&&& .:' | ||
| MMMMM88&&&&&&:' | ||
| MMMMM88&&&&&& | ||
| .:MMMMM88&&&&&& | ||
| .:' MMMMM88&&&& | ||
| .:' .:'MMM8&&&' | ||
| :' .:' | ||
| '::' jgs |
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,11 @@ | ||
|
|
||
|
|
||
| * + | ||
| ' | | ||
| () .-.,="``"=. - o - | ||
| '=/_ \ | | ||
| * | '=._ | | ||
| \ `=./`, ' | ||
| . '=.__.=' `=' * | ||
| + + | ||
| O * ' . jgs |
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 @@ | ||
| . + . . . . . . | ||
| . . . * | ||
| . * . . . . . . + . | ||
| "You Are Here" . . + . . . | ||
| . | . . . . . . | ||
| | . . . +. + . | ||
| \|/ . . . . | ||
| . . V . * . . . . + . | ||
| + . . . + | ||
| . . + .+. . | ||
| . . . + . . . . . | ||
| . . . . . . . . ! / | ||
| * . . . + . . - O - | ||
| . . . + . . * . . / | | ||
| . + . . . .. + . | ||
| . . . . * . * . +.. . * | ||
| . . . . . . . . + . . + |
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,163 @@ | ||
| require "colorize" | ||
| require_relative "planet.rb" | ||
| require_relative "solar_system.rb" | ||
|
|
||
| def main | ||
| display(load_solar_system_program) | ||
| continue = true | ||
| while continue | ||
| puts options | ||
| continue = do_option(get_option) | ||
| end | ||
| display(good_bye) | ||
| end | ||
|
|
||
| def display(string, char = true, lag = 0.03) | ||
| if char | ||
| count = 0 | ||
| string.each_char do |ch| | ||
| print ch | ||
| sleep lag if count < 100 | ||
| count += 1 | ||
| end | ||
| else | ||
| puts string | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| def load_solar_system_program | ||
| @solar_system = SolarSystem.new("Err") | ||
|
|
||
| create_system(solar_system) | ||
| return "Welcome to the".cyan + " Solar System Program.".light_magenta.bold \ | ||
| + read_file("./art/solar.txt").yellow + "\n\nYou are in the Solar System of #{solar_system.name}.\n".cyan | ||
| end | ||
|
|
||
| def solar_system | ||
| return @solar_system | ||
| end | ||
|
|
||
| def create_system(solar_system) | ||
| solar_system.add_planet(Planet.new("Willerr", "blue", 5.972e24, 1.496e28, | ||
| "raining rainbows")) | ||
| solar_system.add_planet(Planet.new("Saverr", "amber", 9.34e54, 2.345e23, | ||
| "saving time by reversing spin")) | ||
| solar_system.add_planet(Planet.new("Katerr", "green", 2.342e33, 4.234e43, | ||
| "being made of dolphins")) | ||
| solar_system.add_planet(Planet.new("Singherr", "onyx", 4.23e23, 46.2e23, | ||
| "emmitting song-like sounds")) | ||
| end | ||
|
|
||
| def options | ||
| string_of_options = "\n\nEnter ".green + "LIST".cyan.on_blue.italic + " to display all the planets in system.".green \ | ||
| + "\nEnter ".green + "ADD ".cyan.on_blue.italic + " to add planets".green \ | ||
| + "\nEnter ".green + "CALC".cyan.on_blue.italic + " to calculate the distance between two planets".green \ | ||
| + "\nEnter ".green + "INFO".cyan.on_blue.italic + " to display information about a planet".green \ | ||
| + "\nEnter ".green + "Q ".cyan.on_blue.italic + " to quit program\n".green | ||
| return string_of_options | ||
| end | ||
|
|
||
| def get_option | ||
| print "\nPlease Enter Selection: ".cyan | ||
| user_input = gets.chomp.upcase | ||
| return user_input if ["LIST", "ADD", "CALC", "INFO", "Q"].include?(user_input) | ||
| display("Hmm... ", true, 0.5) | ||
| puts "I don't understand \"#{user_input}\".".red.bold.underline | ||
| sleep 1 | ||
| get_option | ||
| end | ||
|
|
||
| def do_option(option_key) | ||
| case option_key | ||
| when "LIST" | ||
| display(solar_system.list_planets.yellow) | ||
| when "ADD" | ||
| user_add_planet | ||
| when "CALC" | ||
| user_calc_distance | ||
| when "INFO" | ||
| display(user_info_planet.cyan) | ||
| sleep 1 | ||
| when "Q" | ||
| return false | ||
| end | ||
| end | ||
|
|
||
| def user_add_planet | ||
| display("\nTo add a planet follow the prompts: \n".yellow) | ||
| print "Name? ".yellow | ||
| name = gets.chomp.capitalize | ||
| print "Color? ".yellow | ||
| color = gets.chomp.downcase | ||
| print "Mass in kg? ".yellow | ||
| mass = gets.chomp.to_i | ||
| print "Distance from sun in km? ".yellow | ||
| distance = gets.chomp.to_i | ||
| print "Fun fact? ".yellow | ||
| fun_fact = gets.chomp | ||
| begin | ||
| solar_system.add_planet(Planet.new(name, color, mass, distance, fun_fact)) | ||
| display("\nCongratulations #{solar_system.planets[-1].name} Succesfully Added!!".cyan.on_blue) | ||
| puts read_file("./art/planet.txt").light_magenta | ||
| rescue ArgumentError => error_message | ||
| display("\nError: #{error_message} \nReselect option from main menu to try again.".red.underline.bold) | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| def user_calc_distance | ||
| print "\nEnter first planet: ".yellow | ||
| planet1 = get_planet | ||
| return true if !planet1 | ||
| print "Enter second planet: ".yellow | ||
| planet2 = get_planet | ||
| return true if !planet2 | ||
| begin | ||
| distance = solar_system.distance_between(planet1, planet2) | ||
| puts read_file("./art/distance.txt").blue.bold | ||
| display("\nDirections from #{planet1.name.upcase} to #{planet2.name.upcase}:".light_magenta) | ||
| display("ONWARD -> ".cyan.on_blue) | ||
| display("%0.3e km ".cyan.on_blue % [distance]) | ||
| display("\nIt will take %0.2e light years, expected day of arrival: May 4th".magenta % [distance / 1.057e13]) | ||
| sleep 1 | ||
| rescue ArgumentError => error_message | ||
| display("\nError: #{error_message} \nReselect option from main menu to try again.".red.underline.bold) | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| def user_info_planet | ||
| print "\nWhich planet would you like more information on? ".yellow | ||
| planet = get_planet | ||
| return planet.summary if planet | ||
| return "Try using the numeric tags associated with planets from LIST command.".red | ||
| end | ||
|
|
||
| def get_planet | ||
| planet_name = gets.chomp.capitalize | ||
| begin | ||
| planet = solar_system.find_planet_by_name(planet_name) | ||
| rescue ArgumentError | ||
| planet = planet_name.to_i.to_s == planet_name ? solar_system.planets[planet_name.to_i - 1] : nil | ||
| if !solar_system.is_a_Planet?(planet) | ||
| display("Hmm... ", true, 0.5) | ||
| puts "#{planet_name} is not in the system of #{solar_system.name}".cyan | ||
| end | ||
| end | ||
| return planet | ||
| end | ||
|
|
||
| def read_file(file) | ||
| read = "" | ||
| File.open(file, "r") do |f| | ||
| read += f.read | ||
| end | ||
| return read | ||
| end | ||
|
|
||
| def good_bye | ||
| return "\n\nGoodbye! Visit the #{solar_system.name} system again soon! Safe Travels!\n".magenta.bold.italic.underline + read_file("./art/unicorn.txt").light_magenta.bold + "\n" | ||
| end | ||
|
|
||
| main |
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.capitalize | ||
| @color = color.downcase | ||
| @mass_kg = mass_kg > 0 ? mass_kg : (raise ArgumentError.new("Mass must be greater than 0.")) | ||
| @distance_from_sun_km = distance_from_sun_km > 0 ? distance_from_sun_km : (raise ArgumentError.new("Distance must be greater than 0.")) | ||
| @fun_fact = fun_fact.downcase | ||
| end | ||
|
|
||
| def summary | ||
| return "\n#{name} is a #{color} planet that is %0.2e km from it's sun. \nIt has a mass of %0.2e kg and \nis known for #{fun_fact}." % [distance_from_sun_km, mass_kg] | ||
| 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,46 @@ | ||
| class SolarSystem | ||
| attr_reader :name, :planets | ||
|
|
||
| def initialize(name) | ||
| @name = name.capitalize | ||
| @planets = Array.new | ||
| end | ||
|
|
||
| def add_planet(planet) | ||
| raise ArgumentError.new("#{planet.capitalize} is not a Planet") if !is_a_Planet?(planet) | ||
| if planets.any? do |logged_planet| | ||
| planet.name == logged_planet.name | ||
| end | ||
| raise ArgumentError.new("#{planet.name}\'s name is in use.") | ||
| else | ||
| @planets << planet | ||
| end | ||
| return true | ||
| end | ||
|
|
||
| def list_planets | ||
| string_planets = "\nPlanets orbiting #{self.name}\n" | ||
| @planets.each_with_index do |planet, i| | ||
| string_planets += "#{i + 1}. #{planet.name}\n" | ||
| end | ||
| return string_planets | ||
| end | ||
|
|
||
| def find_planet_by_name(name) | ||
| @planets.each do |planet| | ||
| return planet if planet.name == name.capitalize | ||
| end | ||
| raise ArgumentError.new("No planet by #{name} found.") | ||
| end | ||
|
|
||
| def distance_between(planet1, planet2) | ||
| if is_a_Planet?(planet1) && is_a_Planet?(planet2) | ||
| return (planet1.distance_from_sun_km - planet2.distance_from_sun_km).abs.to_i | ||
| end | ||
| raise ArgumentError.new("#{planet1} and/or #{planet2} not of type Planet") | ||
| end | ||
|
|
||
| def is_a_Planet?(planet) | ||
| return planet.instance_of?(Planet) | ||
| 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,57 @@ | ||
| gem "minitest", ">= 5.0.0" | ||
| require "minitest/pride" | ||
| require "minitest/autorun" | ||
| require_relative "../lib/planet" | ||
|
|
||
| describe "Planet" do | ||
| let (:earth) { | ||
| Planet.new("Earth", "blue-green", 5.972e24, 1.496e8, "Only planet known to support life") | ||
| } | ||
|
|
||
| it "is an instance of Planet" do | ||
| expect(earth).must_be_instance_of Planet | ||
| end | ||
|
|
||
| it "has a name" do | ||
| expect(earth.name).must_equal "Earth" | ||
| end | ||
|
|
||
| it "has a color" do | ||
| expect(earth.color).must_equal "blue-green" | ||
| end | ||
|
|
||
| it "has a mass" do | ||
| expect(earth.mass_kg).must_be_close_to 5.972e24, 0.01 | ||
| end | ||
|
|
||
| it "has a distance from sun" do | ||
| expect(earth.distance_from_sun_km).must_be_close_to 1.496e8, 0.01 | ||
| end | ||
|
|
||
| it "has a fun fact" do | ||
| expect(earth.fun_fact).must_equal "only planet known to support life" | ||
| end | ||
|
|
||
| describe "summary" do | ||
| it "returns a string" do | ||
| expect(earth.summary).must_be_kind_of String | ||
| end | ||
| it "returns a summary of planet's attributes" do | ||
| expect(earth.summary).must_equal "\nEarth is a blue-green planet that is 1.50e+08 km from it's sun. \nIt has a mass of 5.97e+24 kg and \nis known for only planet known to support life." | ||
| end | ||
| end | ||
|
|
||
| describe "test edge case for distance and mass" do | ||
| it "0 mass will raise argument error" do | ||
| expect { | ||
| Planet.new("Invisible", "clear", 0, 234230, " located everywhere, but nowhere") | ||
| }.must_raise ArgumentError | ||
| end | ||
|
|
||
| it "0 distance will raise argument error" do | ||
| expect { | ||
| Planet.new("Rock", "jelly", 34535555, 0, " located everywhere, but nowhere") | ||
| }.must_raise ArgumentError | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
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.
Fabulous use of minitest-pride!