Skip to content

Instantly share code, notes, and snippets.

@Industrial
Created May 30, 2012 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Industrial/4e7f524568dec1e673cb to your computer and use it in GitHub Desktop.
Save Industrial/4e7f524568dec1e673cb to your computer and use it in GitHub Desktop.
class Shuffler
attr_reader :list
def initialize(list)
@list = list
end
def shuffle
i = @list.length - 1
while i >= 0
x = rand(i)
@list[i], @list[x] = @list[x], @list[i]
i = i - 1
end
end
end
require './Shuffler.rb'
deck = []
for suit in ['S', 'H', 'D', 'C']
for card in ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'J', 'Q', 'K', 'A']
deck.push "#{suit}#{card}"
end
end
describe Shuffler, '#shuffle' do
it 'returns a randomized deck of cards' do
shuffler = Shuffler.new deck.dup
shuffler.shuffle()
shuffler.list.should_not == deck
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment