Skip to content

Commit 476f439

Browse files
committed
#33 Fix NullReferenceException with test
1 parent 641b773 commit 476f439

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Advanced.Algorithms/Geometry/BentleyOttmann.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Advanced.Algorithms.Geometry
1010
/// </summary>
1111
public class BentleyOttmann
1212
{
13-
private readonly int precision;
1413
private readonly PointComparer pointComparer;
1514

1615
private HashSet<Event> verticalHorizontalLines;
@@ -30,7 +29,6 @@ public class BentleyOttmann
3029

3130
public BentleyOttmann(int precision = 5)
3231
{
33-
this.precision = precision;
3432
pointComparer = new PointComparer();
3533

3634
Tolerance = Math.Round(Math.Pow(0.1, precision), precision);
@@ -64,7 +62,7 @@ private void initialize(IEnumerable<Line> lineSegments)
6462
eventQueueLookUp = new HashSet<Event>(rightLeftEventLookUp.SelectMany(x => new[] {
6563
x.Key,
6664
x.Value
67-
}), new PointComparer());
65+
}));
6866

6967
eventQueue = new BHeap<Event>(SortDirection.Ascending, eventQueueLookUp, new EventQueueComparer());
7068
}

tests/Advanced.Algorithms.Tests/Geometry/BentleyOttmann_Tests.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Advanced.Algorithms.Tests.Geometry
1111
public class BentleyOttmann_Tests
1212
{
1313
[TestMethod]
14-
public void BentleyOttmann_Smoke_Test()
14+
public void BentleyOttmann_Smoke_Test_1()
1515
{
1616
var lines = new List<Line>();
1717

@@ -31,6 +31,26 @@ public void BentleyOttmann_Smoke_Test()
3131
Assert.AreEqual(expectedIntersections.Count, actualIntersections.Count);
3232
}
3333

34+
[TestMethod]
35+
public void BentleyOttmann_Smoke_Test_2()
36+
{
37+
var lines = new List<Line>();
38+
39+
var s1 = new Line(new Point(100, 0), new Point(150, 130));
40+
var s2 = new Line(new Point(20, 80), new Point(80, 70));
41+
var s3 = new Line(new Point(80, 70), new Point(50, 100));
42+
43+
lines.AddRange(new[] { s1, s2, s3 });
44+
45+
var expectedIntersections = getExpectedIntersections(lines);
46+
47+
var bentleyOttmannAlgorithm = new BentleyOttmann();
48+
49+
var actualIntersections = bentleyOttmannAlgorithm.FindIntersections(lines);
50+
51+
Assert.AreEqual(expectedIntersections.Count, actualIntersections.Count);
52+
}
53+
3454
[TestMethod]
3555
public void BentleyOttmann_Vertical_Lines_Test()
3656
{

0 commit comments

Comments
 (0)