(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func TestLineIntersection(t *testing.T) { |
| 124 | //Parallel lines |
| 125 | one := Line{ |
| 126 | Point{0, 0}, |
| 127 | Point{1, 1}} |
| 128 | two := Line{ |
| 129 | Point{0, 1}, |
| 130 | Point{1, 2}} |
| 131 | |
| 132 | point, intersect := LineIntersection(one, two) |
| 133 | |
| 134 | if intersect { |
| 135 | t.Errorf("Lines %v and %v should not intersect, they are parallel. Intersection at: %v.", one, two, point) |
| 136 | } |
| 137 | |
| 138 | //Collinear lines |
| 139 | one = Line{ |
| 140 | Point{0, 0}, |
| 141 | Point{1, 1}} |
| 142 | two = Line{ |
| 143 | Point{2, 2}, |
| 144 | Point{3, 3}} |
| 145 | |
| 146 | point, intersect = LineIntersection(one, two) |
| 147 | |
| 148 | if intersect { |
| 149 | t.Errorf("Lines %v and %v should not intersect, they are collinear. Intersection at: %v", one, two, point) |
| 150 | } |
| 151 | |
| 152 | //intersecting lines |
| 153 | one = Line{ |
| 154 | Point{0, 0}, |
| 155 | Point{1, 1}} |
| 156 | two = Line{ |
| 157 | Point{0, 1}, |
| 158 | Point{1, 1}} |
| 159 | |
| 160 | point, intersect = LineIntersection(one, two) |
| 161 | |
| 162 | if !intersect { |
| 163 | t.Errorf("Lines %v and %v should intersect.", one, two) |
| 164 | } |
| 165 | |
| 166 | if intersect && (point != Point{1, 1}) { |
| 167 | t.Errorf("Lines %v and %v should intersect at point {1, 1}, but they are intersecting at %v.", one, two, point) |
| 168 | } |
| 169 | |
| 170 | } |
| 171 | |
| 172 | func TestPointEqual(t *testing.T) { |
| 173 | data := []struct { |
nothing calls this directly
no test coverage detected