Skip to content

@dnagir /cycle_tracks.rb secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
def skip_tracks(playlist, skip)
if skip > 0
skip.times { playlist.push playlist.shift }
else
skip.abs.times { playlist.unshift playlist.pop }
end
playlist
end
Feature: Track skipping
In order to ignore some tracks
I want to be able to skip them
Scenario Outline: Skipping forward
Given the playlist "a, b, c, d"
When I skip <skip> track forward
Then I should have the playlist "<result>"
Examples:
| skip | result |
| 1 | b,c,d,a |
| 2 | c,d,a,b |
| 3 | d,a,b,c |
| 4 | a,b,c,d |
| 5 | b,c,d,a |
| 6 | c,d,a,b |
Scenario Outline: Skipping backward
Given the playlist "a, b, c, d"
When I skip <skip> track backward
Then I should have the playlist "<result>"
Examples:
| skip | result |
| 1 | d,a,b,c |
| 2 | c,d,a,b |
| 3 | b,c,d,a |
| 4 | a,b,c,d |
| 5 | d,a,b,c |
| 6 | c,d,a,b |
Given /^the playlist "([^"]*)"$/ do |list|
@playlist = list.split(',').map { |x| x.strip }
end
When /^I skip (\d+) tracks? (\w+)$/ do |count, direction|
skip_count = count.to_i * (direction == 'forward' ? 1 : -1)
@playlist = skip_tracks(@playlist, skip_count)
end
Then /^I should have the playlist "([^"]*)"$/ do |list|
@playlist.should == list.split(',').map { |x| x.strip }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.