1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
11 class TestHistory < Test::Unit::TestCase
13 @history = History.new("initial_state")
16 def test_initial_state
17 assert_equal 0, @history.current
18 assert_equal "initial_state", @history.state
19 assert_nil @history.move
20 assert_equal 1, @history.size
24 @history.add_move("new_state", "first_move")
25 assert_equal 1, @history.current
26 assert_equal "new_state", @history.state
27 assert_equal "first_move", @history.move
28 assert_equal 2, @history.size
29 @history.add_move("new_new_state", "second_move")
30 assert_equal 2, @history.current
31 assert_equal "new_new_state", @history.state
32 assert_equal "second_move", @history.move
33 assert_equal 3, @history.size
36 def test_back_on_first
37 assert_raise History::OutOfBound do
39 assert_equal 0, @history.current
43 def test_forward_on_last
44 @history.add_move("new_state", "first_move")
45 assert_raise History::OutOfBound do
47 assert_equal 1, @history.current
52 @history.add_move("new_state", "first_move")
54 assert_equal 0, @history.current
58 @history.add_move("new_state", "first_move")
61 assert_equal 1, @history.current
64 def test_overwrite_moves
65 @history.add_move("new_state1", "first_move1")
66 @history.add_move("new_new_state1", "second_move1")
69 @history.add_move("new_state2", "first_move2")
70 assert_equal 1, @history.current
71 assert_equal "new_state2", @history.state
72 assert_equal "first_move2", @history.move
73 assert_equal 2, @history.size