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.
8 module ValidationHelper
11 if args.last.instance_of? Hash
20 @state.move_factory.new(*(args + [opts]))
22 @state.move_factory.new(*(args.to_enum(:each_slice, 2).map{|x| Point.new(*x) } + [opts]))
24 raise ArgumentError.new("Could not unpack move using #{args.size} parameters")
28 def unpack_point(*args)
37 def assert_valid(*args)
38 move = unpack_move(*args)
39 assert @validate[move]
40 yield move if block_given?
43 def assert_not_valid(*args)
44 assert ! @validate[unpack_move(*args)]
47 def assert_piece(color, type, *point)
48 p = unpack_point(*point)
50 exp = @state.piece_factory.new(color, type)
51 assert_not_nil piece, "#{exp} expected on #{p}, nothing found"
52 assert_equal exp, piece, "#{exp} expected on #{p}, #{piece} found"
53 yield piece if block_given?
56 def assert_no_piece(*point)
57 assert_nil @board[unpack_point(*point)]
61 move = unpack_move(*args)
62 assert @validate[move]
66 def assert_pool(color, type, number)
67 piece = @state.piece_factory.new(color, type)
68 assert_equal number, @state.pool(color).pieces[piece]
71 def serialize(serializer, *args)
72 move = unpack_move(*args)
73 serializer.serialize(move, @state)