forked from Zalgo2462/VoronoiLib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFortuneAlgorithmTest.cs
96 lines (89 loc) · 3.28 KB
/
FortuneAlgorithmTest.cs
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
88
89
90
91
92
93
94
95
96
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VoronoiLib;
using VoronoiLib.Structures;
namespace VoronoiLibTests
{
[TestClass]
public class FortuneAlgorithmTest
{
[TestMethod]
public void FortuneThreePoints()
{
var points = new List<FortuneSite>
{
new FortuneSite(100, 100),
new FortuneSite(200, 200),
new FortuneSite(200, 150)
};
var edges = FortunesAlgorithm.Run(points, 0 , 0, 600, 600);
var edge = edges.First;
//edge 1
Assert.AreEqual(125, edge.Value.Start.X);
Assert.AreEqual(175, edge.Value.Start.Y);
Assert.AreEqual(0, edge.Value.End.X);
Assert.AreEqual(300, edge.Value.End.Y);
Assert.IsNotNull(edge.Next);
edge = edge.Next;
//edge 2
Assert.AreEqual(600, edge.Value.Start.X);
Assert.AreEqual(175, edge.Value.Start.Y);
Assert.AreEqual(125, edge.Value.End.X);
Assert.AreEqual(175, edge.Value.End.Y);
Assert.IsNotNull(edge.Next);
edge = edge.Next;
//edge 3
Assert.AreEqual(212.5, edge.Value.Start.X);
Assert.AreEqual(0, edge.Value.Start.Y);
Assert.AreEqual(125, edge.Value.End.X);
Assert.AreEqual(175, edge.Value.End.Y);
Assert.IsNull(edge.Next);
}
[TestMethod]
public void FortuneColinearPoints()
{
var points = new List<FortuneSite>
{
new FortuneSite(300, 100),
new FortuneSite(300, 300),
new FortuneSite(300, 500)
};
var edges = FortunesAlgorithm.Run(points, 0, 0, 600, 600);
var edge = edges.First;
Assert.AreEqual(600, edge.Value.Start.X);
Assert.AreEqual(400, edge.Value.Start.Y);
Assert.AreEqual(0, edge.Value.End.X);
Assert.AreEqual(400, edge.Value.End.Y);
Assert.IsNotNull(edge.Next);
edge = edge.Next;
Assert.AreEqual(600, edge.Value.Start.X);
Assert.AreEqual(200, edge.Value.Start.Y);
Assert.AreEqual(0, edge.Value.End.X);
Assert.AreEqual(200, edge.Value.End.Y);
Assert.IsNull(edge.Next);
}
[TestMethod]
public void FortunePointBreak()
{
var points = new List<FortuneSite>
{
new FortuneSite(100, 100),
new FortuneSite(500, 100),
new FortuneSite(300, 200)
};
var edges = FortunesAlgorithm.Run(points, 0, 0, 600, 600);
var edge = edges.First;
Assert.AreEqual(325, edge.Value.Start.X);
Assert.AreEqual(0, edge.Value.Start.Y);
Assert.AreEqual(600, edge.Value.End.X);
Assert.AreEqual(550, edge.Value.End.Y);
Assert.IsNotNull(edge.Next);
edge = edge.Next;
Assert.AreEqual(275, edge.Value.Start.X);
Assert.AreEqual(0, edge.Value.Start.Y);
Assert.AreEqual(0, edge.Value.End.X);
Assert.AreEqual(550, edge.Value.End.Y);
Assert.IsNull(edge.Next);
}
}
}