Parse castling in verbose notation.
[kaya.git] / test / interaction / test_operation_history.rb
blob8f83996b111d96bdae36f0827c11c7d3084b6276
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 'interaction/operation_history'
11 class TestOperationHistory < Test::Unit::TestCase
12   def setup
13     @operations = OperationHistory.new
14   end
15   
16   def test_initial_state
17     assert_equal 0, @operations.size
18     assert_equal -1, @operations.current
19   end
20   
21   def test_add_operation
22     @operations << 'op'
23     assert_equal 1, @operations.size
24     assert_equal 0, @operations.current
25   end
26   
27   def test_add_then_undo
28     @operations << 'op'
29     assert_equal 'op', @operations.undo_operation
30     assert_equal 1, @operations.size
31     assert_equal -1, @operations.current
32   end
33   
34   def test_undo_at_beginning
35     @operations << 'op'
36     assert_equal 'op', @operations.undo_operation
37     assert_nil @operations.undo_operation
38   end
39   
40   def test_add_undo_redo
41     @operations << 'op'
42     assert_equal 'op', @operations.undo_operation
43     assert_equal 'op', @operations.redo_operation
44     assert_equal 1, @operations.size
45     assert_equal 0, @operations.current
46   end
47   
48   def test_navigate
49     (1..10).each do |i|
50       @operations << "op#{i}"
51     end
52     assert_equal 10, @operations.size
53     assert_equal 9, @operations.current
54     
55     3.times { @operations.undo_operation }
56     
57     assert_equal 6, @operations.current
58     
59     assert_equal "op8", @operations.redo_operation
60     assert_equal "op9", @operations.redo_operation
61     
62     @operations.undo_operation
63     
64     assert_equal "op9", @operations.redo_operation
65     assert_equal "op10", @operations.redo_operation
66     
67     assert_equal 9, @operations.current
68   end
69   
70   def test_redo_after_move
71     @operations << "move"
72     assert_equal 1, @operations.size
73     assert_equal 0, @operations.current
74     @operations.undo_operation
75     assert_equal 1, @operations.size
76     assert_equal -1, @operations.current
77     @operations << "move"
78     assert_equal 1, @operations.size
79     assert_equal 0, @operations.current
80   end
81 end