Add licence and installation instructions.
[kaya.git] / test / test_history.rb
blobba56553d5b345dce4fb064f34ca1a6d742b7cb01
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
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.
8 require 'test/unit'
9 require 'history'
11 class TestHistory < Test::Unit::TestCase
12   def setup
13     @history = History.new("initial_state")
14   end
15   
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
21   end
22   
23   def test_add_move
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
34   end
35   
36   def test_back_on_first
37     assert_raise History::OutOfBound do
38       @history.back
39       assert_equal 0, @history.current
40     end
41   end
42   
43   def test_forward_on_last
44     @history.add_move("new_state", "first_move")
45     assert_raise History::OutOfBound do
46       @history.forward
47       assert_equal 1, @history.current
48     end
49   end
50   
51   def test_back
52     @history.add_move("new_state", "first_move")
53     @history.back
54     assert_equal 0, @history.current
55   end
56   
57   def test_forward
58     @history.add_move("new_state", "first_move")
59     @history.back
60     @history.forward
61     assert_equal 1, @history.current
62   end
63   
64   def test_overwrite_moves
65     @history.add_move("new_state1", "first_move1")
66     @history.add_move("new_new_state1", "second_move1")
67     @history.back
68     @history.back
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
74   end
75 end