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.
9 require 'interaction/operation_history'
11 class TestOperationHistory < Test::Unit::TestCase
13 @operations = OperationHistory.new
16 def test_initial_state
17 assert_equal 0, @operations.size
18 assert_equal -1, @operations.current
21 def test_add_operation
23 assert_equal 1, @operations.size
24 assert_equal 0, @operations.current
27 def test_add_then_undo
29 assert_equal 'op', @operations.undo_operation
30 assert_equal 1, @operations.size
31 assert_equal -1, @operations.current
34 def test_undo_at_beginning
36 assert_equal 'op', @operations.undo_operation
37 assert_nil @operations.undo_operation
40 def test_add_undo_redo
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
50 @operations << "op#{i}"
52 assert_equal 10, @operations.size
53 assert_equal 9, @operations.current
55 3.times { @operations.undo_operation }
57 assert_equal 6, @operations.current
59 assert_equal "op8", @operations.redo_operation
60 assert_equal "op9", @operations.redo_operation
62 @operations.undo_operation
64 assert_equal "op9", @operations.redo_operation
65 assert_equal "op10", @operations.redo_operation
67 assert_equal 9, @operations.current
70 def test_redo_after_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
78 assert_equal 1, @operations.size
79 assert_equal 0, @operations.current