added Algorithms/SierpinskiTriangle.cs
This commit is contained in:
1 parent
6acd8c8ff1
commit
a832521bda
7 files changed
+137
-4
No files matched your search
@@ -0,0 +1,32 @@
|
||||
namespace Algorithms.Tests;
|
||||
using Algorithms;
|
||||
|
||||
[TestClass]
|
||||
public class PointTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestToString()
|
||||
{
|
||||
Point point = new Point(0, 1);
|
||||
Assert.AreEqual("{\"x\": 0, \"y\": 1}", point.ToString());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMidPointOf(){
|
||||
Point point1 = new Point(2, 6);
|
||||
Point point2 = new Point(5, 3);
|
||||
Point res = point1.MidPointOf(point2);
|
||||
|
||||
Assert.AreEqual(3.5, res.X(), 0.001);
|
||||
Assert.AreEqual(4.5, res.Y(), 0.001);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestDistance(){
|
||||
Point point1 = new Point(2, 6);
|
||||
Point point2 = new Point(5, 3);
|
||||
Assert.AreEqual(4.24264, point1.Distance(point2), 0.001);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Algorithms.Tests;
|
||||
using Algorithms;
|
||||
|
||||
[TestClass]
|
||||
public class SierpinskiTriangleTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestGeneration()
|
||||
{
|
||||
SierpinskiTriangle st = new SierpinskiTriangle(new Random(666));
|
||||
Assert.AreEqual(10, st.GenerateRandomPath(new Point(2, 3), 10).Count());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace Algorithms.Tests;
|
||||
using Algorithms;
|
||||
|
||||
[TestClass]
|
||||
public class TriangleTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestEquilateral()
|
||||
{
|
||||
Triangle triangle = Triangle.Equilateral(10);
|
||||
Assert.AreEqual(10, triangle.Vertex1.Distance(triangle.Vertex2), 0.001);
|
||||
Assert.AreEqual(10, triangle.Vertex2.Distance(triangle.Vertex3), 0.001);
|
||||
Assert.AreEqual(10, triangle.Vertex3.Distance(triangle.Vertex1), 0.001);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetVertexById(){
|
||||
Triangle triangle = Triangle.Equilateral(10);
|
||||
Assert.AreEqual(triangle.Vertex1, triangle.GetVertexById(0));
|
||||
Assert.AreEqual(triangle.Vertex2, triangle.GetVertexById(1));
|
||||
Assert.AreEqual(triangle.Vertex3, triangle.GetVertexById(2));
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestRandomSummit(){
|
||||
Triangle triangle = Triangle.Equilateral(10);
|
||||
Random random = new Random(666);
|
||||
|
||||
Assert.AreEqual(triangle.Vertex2, triangle.RandomSummit(random));
|
||||
Assert.AreEqual(triangle.Vertex1, triangle.RandomSummit(random));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user