4 class TestHistory < Test::Unit::TestCase
6 @history = History.new("initial_state")
10 assert_equal 0, @history.current
11 assert_equal "initial_state", @history.state
12 assert_nil @history.move
13 assert_equal 1, @history.size
17 @history.add_move("new_state", "first_move")
18 assert_equal 1, @history.current
19 assert_equal "new_state", @history.state
20 assert_equal "first_move", @history.move
21 assert_equal 2, @history.size
22 @history.add_move("new_new_state", "second_move")
23 assert_equal 2, @history.current
24 assert_equal "new_new_state", @history.state
25 assert_equal "second_move", @history.move
26 assert_equal 3, @history.size
29 def test_back_on_first
30 assert_raise History::OutOfBound do
32 assert_equal 0, @history.current
36 def test_forward_on_last
37 @history.add_move("new_state", "first_move")
38 assert_raise History::OutOfBound do
40 assert_equal 1, @history.current
45 @history.add_move("new_state", "first_move")
47 assert_equal 0, @history.current
51 @history.add_move("new_state", "first_move")
54 assert_equal 1, @history.current
57 def test_overwrite_moves
58 @history.add_move("new_state1", "first_move1")
59 @history.add_move("new_new_state1", "second_move1")
62 @history.add_move("new_state2", "first_move2")
63 assert_equal 1, @history.current
64 assert_equal "new_state2", @history.state
65 assert_equal "first_move2", @history.move
66 assert_equal 2, @history.size