Fix minishogi notation, enabling play against gnuminishogi.
[kaya/ydirson.git] / test / test_point.rb
blob9db53301ab19bb5e3c43a793a3e5b66ceb9df0a8
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 'point'
11 class TestPoint < Test::Unit::TestCase
12   def test_getters
13     p = Point.new(3, 4)
14     assert_equal 3, p.x
15     assert_equal 4, p.y
16   end
17   
18   def test_equality
19     assert_equal Point.new(4, 5), Point.new(4, 5)
20     assert_not_equal Point.new(4, 5), Point.new(1, 2)
21   end
22   
23   def test_sum
24     assert_equal Point.new(7, 1), Point.new(3, 4) + Point.new(4, -3)
25   end
26   
27   def test_difference
28     assert_equal Point.new(4, 5), Point.new(10, 2) - Point.new(6, -3)
29   end
30   
31   def test_scaling
32     assert_equal Point.new(6, 2), Point.new(3, 1) * 2
33     assert_equal Point.new(3, 9), Point.new(12, 36) / 4
34   end
35   
36   def test_unit
37     assert_equal Point.new(1, 1), Point.new(3, 3).unit
38     assert_equal Point.new(1, 0), Point.new(4, 0).unit
39     assert_equal Point.new(0, 0), Point.new(0, 0).unit
40     assert_equal Point.new(-1, 1), Point.new(-5, 5).unit
41   end
42   
43   def test_numeric_unit
44     assert_equal -1, -5.unit
45     assert_equal 0, 0.unit
46     assert_equal 1, 83.unit
47     assert_equal -1, -0.34.unit
48   end
49   
50   def test_to_coord
51     assert_equal 'e4', Point.new(4, 4).to_coord(8)
52     assert_equal 'b9', Point.new(1, 0).to_coord(9)
53   end
54   
55   def test_from_coord
56     assert_equal Point.new(4, 3), Point.from_coord('e5', 8)
57     assert_equal Point.new(0, 0), Point.from_coord('a8', 8)
58     assert_equal Point.new(6, 2), Point.from_coord('g6', 8)
59   end
60 end