Conversation
…ment the code for wave-2 and then will uncomment it later when adding wave-2 code
…ompleted wave-2 yet
Solar SystemWhat We're Looking For
Fantastic work on this project, Xinran! Your code style is clean, and I can tell that you used OO and composition correctly and well. In particular, you did a really excellent job of creating helper methods in You ended up having a bug in your code, though. I've added a comment to detail it. Also, the project asked for a feature to show planet details, but I don't see a good way for me to do this with your current project submission. That being said, your code looks great! Also, good job on writing some great unit tests! Good work! |
| def list_planets | ||
| list_planets = "Planets orbiting #{@star_name}" | ||
| i = 0 | ||
| @planets.each do |planet| |
There was a problem hiding this comment.
Consider refactoring this to use .each_with_index because .each_with_index allows access for an index variable (so you won't need i = 0 or i += 1)
|
|
||
| def find_planet_by_name(name) | ||
| @planets.each do |planet| | ||
| return planet if planet.name.downcase == name.downcase |
| end | ||
|
|
||
| def find_planet_by_name(name) | ||
| @planets.each do |planet| |
There was a problem hiding this comment.
An idea for refactoring: using the .find method!
| while (input.class != Integer && input.class != Float) || input.to_f <= 0 | ||
| print "Invalid! Input is not a positive value.\nPlease re-input: " | ||
| print ">> " | ||
| input = gets.chomp |
There was a problem hiding this comment.
Your code gets stuck here! To reproduce:
- Run main with
$ ruby main.rb - Input
add planet - For name, input
Dee - For color, input
red - For mass at kg, input
invalid - When asked to re-input, type in
100 - Observe that it still says
Invalid! Input is not a positive value.
My prediction is that you re-assign input to input = gets.chomp, which will always give back a String, but your while loop relies on input being an Integer or Float.
| user_input = gets.chomp | ||
| next_step = check_input(user_input, control_panel, control_panel_message) | ||
| return next_step | ||
| end |
There was a problem hiding this comment.
Amazing work! Great job making this helper method. It works so nicely!
| expect{Planet.new('earth', 'blue-green', 5.972e24, 1.496e8, 222)}.must_raise ArgumentError | ||
| end | ||
|
|
||
| it "won't raise an error" do |
There was a problem hiding this comment.
It might be interesting to use this it block to describe a valid Planet that can also read the correct values of name, color, mass_kg, distance_from_sun_km, and fun_fact
|
|
||
| # wave-2 | ||
| describe "SolarSystem" do | ||
| before do |
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?