Created
December 27, 2010 17:03
-
-
Save Sephi-Chan/756294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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