require 'test/unit' require File.dirname(__FILE__) + '/test_helper' require File.join(File.dirname(__FILE__), 'fixtures/card') class ActsAsDeckTest < Test::Unit::TestCase #:nodoc: fixtures :random_numbers, :cards def initialize(arg) super(arg) end def setup @deck = Card.find :all end def test_randomize_card assert_equal @deck[0].shuffle_key, @deck[1].shuffle_key @deck[0].randomize_card @deck[1].randomize_card assert_not_equal @deck[0].shuffle_key, @deck[1].shuffle_key end def test_shuffle! old_deck = @deck.clone assert_equal old_deck, @deck @deck.shuffle! assert_not_equal old_deck, @deck end def test_shuffle @deck.sort! { |a, b| a.id <=> b.id } temp_deck = @deck.shuffle # deck should still be sorted @deck.length.times do | count | assert_equal @deck[count].id, count+1 end end def test_draw new_deck = @deck.clone # draw is based on pop which pops from the end of the array to the front, # therefore we have to use reverse_each in the test. @deck.each do | card | new_card = new_deck.draw! assert_equal new_card, card end # The deck should now be empty. assert_raises GameDSL::Acts::Deck::EmptyDeckError do new_deck.draw! end end end