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