Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created December 27, 2010 17:03
Show Gist options
  • Save Sephi-Chan/756294 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/756294 to your computer and use it in GitHub Desktop.
class PhaseState
def initialize(*roles)
@state = 0
@roles = roles
end
def current
@roles[@state % @roles.size]
end
def next!
@state += 1
current
end
end
require 'test/unit'
class PhaseStateTest < Test::Unit::TestCase
def test_phase_state
phase_state = PhaseState.new(:killers, :doctor, :detective)
assert(phase_state.current == :killers)
assert(phase_state.next! == :doctor)
assert(phase_state.current == :doctor)
assert(phase_state.next! == :detective)
assert(phase_state.current == :detective)
assert(phase_state.next! == :killers)
assert(phase_state.current == :killers)
assert(phase_state.next! == :doctor)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment