File: test_CollisionDetector.rb

package info (click to toggle)
tj3 3.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,048 kB
  • sloc: ruby: 36,481; javascript: 1,113; sh: 19; makefile: 17
file content (87 lines) | stat: -rw-r--r-- 2,547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = test_CollisionDetector.rb -- The TaskJuggler III Project Management Software
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
#               by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if __FILE__ == $0

require 'test/unit'

require 'taskjuggler/reports/GanttRouter'

class TaskJuggler

class TestCollisionDetector < Test::Unit::TestCase

  def test_collisions
    # To test the collion?() method we use a fix block area and then try
    # various lines that either collide or not.
    #
    #  2,2
    #   +--+
    #   |  |
    #   +--+
    #      4,4
    #
    # We use the same set of lines for horizontal and vertical tests. The
    # first value is the x or y coordinate of the line, the tuple is the start
    # and end coordinate in the other dimension. The third value is the
    # expected result.
    lines = [
      [ [ 1, [0, 1] ], false ],
      [ [ 2, [0, 1] ], false ],
      [ [ 3, [0, 1] ], false ],
      [ [ 4, [0, 1] ], false ],
      [ [ 5, [0, 1] ], false ],
      [ [ 1, [0, 2] ], false ],
      [ [ 2, [0, 2] ], true ],
      [ [ 3, [0, 2] ], true ],
      [ [ 4, [0, 2] ], true ],
      [ [ 5, [0, 2] ], false ],
      [ [ 1, [0, 4] ], false ],
      [ [ 2, [0, 4] ], true ],
      [ [ 3, [0, 4] ], true ],
      [ [ 4, [0, 4] ], true ],
      [ [ 5, [0, 4] ], false ],
      [ [ 1, [0, 5] ], false ],
      [ [ 2, [0, 5] ], true ],
      [ [ 3, [0, 5] ], true ],
      [ [ 4, [0, 5] ], true ],
      [ [ 5, [0, 6] ], false ],
      [ [ 1, [4, 6] ], false ],
      [ [ 2, [4, 6] ], true ],
      [ [ 3, [4, 6] ], true ],
      [ [ 4, [4, 6] ], true ],
      [ [ 5, [4, 6] ], false ],
      [ [ 1, [5, 6] ], false ],
      [ [ 2, [5, 6] ], false],
      [ [ 3, [5, 6] ], false ],
      [ [ 4, [5, 6] ], false ],
      [ [ 5, [5, 6] ], false ]
    ]
    # Try horizontal lines first.
    cd = CollisionDetector.new(10, 10)
    cd.addBlockedZone(2, 2, 3, 3, true, true)

    lines.each do |line|
      assert_equal(line[1], cd.collision?(*(line[0] + [ true ])),
                   "Horizontal #{line[0]} is not #{line[1]}")
    end
    lines.each do |line|
      assert_equal(line[1], cd.collision?(*(line[0] + [ false ])),
                   "Vertical #{line[0]} is not #{line[1]}")
    end
  end

end

end