Add test to Amusement Park Improvements

In the Ruby track, Amusement Park Improvements exercise’s last task does not have sufficient tests, as I see it.

There are three possible cases: to fit the ride without a pass, to have both, and to have a pass without fitting the ride. The tests do not check the last case. Thus, my code:

  def allowed_to_ride?(ride_minimum_height)
    has_pass? # and fits_ride?(ride_minimum_height)
  end

passes.

I happened to stumble across this as I was having syntax difficulties. I’m new to Ruby, but I think this file should be modified as such:

  def test_fits_ride_but_no_pass
    refute Attendee.new(100).allowed_to_ride?(100)
  end

+  def test_does_not_fit_ride_and_pass
+   attendee = Attendee.new(100)
+   attendee.issue_pass!(1)
+   refute attendee.allowed_to_ride?(120)
+ end

  def test_fits_ride_and_pass
    attendee = Attendee.new(100)
    attendee.issue_pass!(1)
    assert attendee.allowed_to_ride?(100)
  end

May I submit a PR?

1 Like

I like it, and I think that we can have these things in the mentoring discussion without requiring the tests changes.

This is a concept exercise, so we would want to make sure that the ideas presented are clear, and not over-extended.

I do not think that there is anything really over-reaching here though.

The current instructions read:

    # Instructions
    
    Continuing your work with the amusement park, you are tasked with writing some utility methods to facilitate checking if an attendee can use a ride.
    
    ## 1. Check if an attendee has a ride pass
    
    Implement the `Attendee#has_pass?` method to return a boolean (`true`/`false`) value based on the presence of a ride pass.
    
    ```ruby
    Attendee.new(100).has_pass?
    # => false
    ```
    
    ## 2. Check if an attendee fits a ride
    
    Implement the `Attendee#fits_ride?` method to see if an attendee fits a ride based on their height.
    The ride's required minimum height is provided as an argument.
    An attendee must have height greater than or equal to ride's required minimum height.
    
    ```ruby
    Attendee.new(140).fits_ride?(100)
    # => true
    ```
    
    ## 3. Check if an attendee is allowed to ride
    
    Implement the `Attendee#allowed_to_ride?` method to see if an attendee is allowed to go on a ride. The ride's required minimum height is provided as an argument. An attendee must have a ride pass and be able to fit the ride.
    
    ```ruby
    attendee = Attendee.new(100)
    attendee.issue_pass!(42)
    attendee.allowed_to_ride?(120)
    # => false
    ```

Should we add something as a fourth point to cover this in the story as well?

To be clear, I think the PR makes sense, but consider the story at the same time.

It will auto-close, but I will open it when I see it. Please link to it here, when that happens, so the conversation can be “linked” (and link to here from there as well).

No, I meant that task number 3 is supposed to have this test case, but doesn’t.

Implement the Attendee#allowed_to_ride? method to see if an attendee is allowed to go on a ride. The ride’s required minimum height is provided as an argument. An attendee must have a ride pass and be able to fit the ride.

The tests currently check two of the possible three scenarios of this task.

So I don’t think we need one - though I feel there’s a misunderstanding in one of our sides :smile:.

Do you mean that we should add it to the mentor notes?

Sounds great! I’ll open a PR after I hear from you (in case I need to modify the mentor notes).

The story shows that it should restrict, and the IRB session shows that it does not allow the ride. So a test makes sense to enforce it.

1 Like

#1550