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.
11 class TestPoint < Test::Unit::TestCase
19 assert_equal Point.new(4, 5), Point.new(4, 5)
20 assert_not_equal Point.new(4, 5), Point.new(1, 2)
24 assert_equal Point.new(7, 1), Point.new(3, 4) + Point.new(4, -3)
28 assert_equal Point.new(4, 5), Point.new(10, 2) - Point.new(6, -3)
32 assert_equal Point.new(6, 2), Point.new(3, 1) * 2
33 assert_equal Point.new(3, 9), Point.new(12, 36) / 4
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
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
51 assert_equal 'e4', Point.new(4, 4).to_coord(8)
52 assert_equal 'b9', Point.new(1, 0).to_coord(9)
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)