Conversation
…d for SolarSystem class
…dated SolarSystem class and main.rb to use new constructor
…with assert_nil for solar_system_test.rb
…d updated its tests
Solar SystemWhat We're Looking For
Eve!!! Your Solar System project is fantastic!!! Your code is thorough and logical. It's clean and covers all of the angles. I'm particularly really thrilled by all of the methods you pulled out into Your code style is also so nice to read; it's dense, but also so concise and elegant. Your code makes me happy to read! I have a couple of comments and suggestions for minor areas of improvement. That being said, your project is great overall. Keep up the good work! |
|
|
||
| def find_planet_by_name(planet_name) | ||
| raise ArgumentError.new("Planet name must be a string") if !(planet_name.instance_of? String) | ||
| planets_by_name = @planets.select {|obj| obj.name == planet_name.capitalize} |
There was a problem hiding this comment.
Nice!
Here's a possible refactoring: using find instead of select. It will give back the element
that matches first. If there is no match, then it will give back nil
| def distance_between(planet_name1, planet_name2) | ||
| raise ArgumentError.new("Arguments must be strings") if !(planet_name1.instance_of? String) || !(planet_name2.instance_of? String) | ||
| first_planet = find_planet_by_name(planet_name1) | ||
| second_planet = find_planet_by_name(planet_name2) |
There was a problem hiding this comment.
Great work re-using the other instance methods!
| return input | ||
| end | ||
|
|
||
| def get_string_input_from_user() |
There was a problem hiding this comment.
Really thorough and thoughtful logic in here. It anticipates a lot of interesting things users can do. Well done
| return Planet.new(name: name, color: color, mass_kg: mass_kg, distance: distance, fact: fact) | ||
| end | ||
|
|
||
| def get_2_planet_names_from_user(solar_system) |
There was a problem hiding this comment.
I love how your code looks in this method! It looks so nice!!
|
|
||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
|
||
| describe "Planet class" do |
There was a problem hiding this comment.
Really really wonderful tests! They're really thorough and cover all of the important parts. Keep it up!
|
|
||
| describe "Planet class" do | ||
| describe "Constructor" do | ||
| it "Error checks input being passed in for mass_kg" do |
There was a problem hiding this comment.
Minor nitpick: It may be helpful to include in the test name that this error happens for negative mass_kg (same as the next distance test)
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod run? What does it do?Hashinstead of an instance of a class?SolarSystemclass used aHashinstead of anArrayto store the list of planets?requirestatements? Which files neededrequires, and which did not? What is the pattern?