public void Test_EightTwelfths() { string result = Decomp.Decompose("8", "13"); Console.WriteLine($"8/13ths: { result }"); Assert.AreEqual("[1/2, 1/9, 1/234]", result.ToString()); }
// [Ignore("There are better tests")] public static void test() { Console.WriteLine("Fixed Tests"); testing(Decomp.Decompose("3", "4"), "[1/2, 1/4]"); testing(Decomp.Decompose("12", "4"), "[3]"); testing(Decomp.Decompose("0", "2"), "[]"); testing(Decomp.Decompose("9", "10"), "[1/2, 1/3, 1/15]"); }
public void Test_Decomp_Greedy() { Queue <double> empty = new Queue <double>(); Queue <double> denoms = new Queue <double>(); StringBuilder sb = new StringBuilder(); denoms = Decomp.GreedyAlgo(3, 4, empty); while (denoms.Count > 0) { sb.Append(denoms.Dequeue().ToString()); if (denoms.Count > 0) { sb.Append(", "); } } Assert.AreEqual("2, 4", sb.ToString()); }
public void Test_Decomp_Difference() { double expectedDiffNumer = 0; double expectedDenom = 8; double diffNumer = Decomp.Difference(1, 2, 2, 4, out double denom); bool diffNumersMatch = false; bool denomIsProduct = false; if (diffNumer == expectedDiffNumer) { diffNumersMatch = true; } if (denom == expectedDenom) { denomIsProduct = true; } Console.WriteLine($"diffNumer: { diffNumer }, out denom: { denom }."); Assert.AreEqual(diffNumersMatch, denomIsProduct); }
public void Test_Decomp_GetGCD() { Assert.AreEqual(20, Decomp.GetGCD(20, 100)); }
public void Test_Decomp_India() { Assert.AreEqual("[1/2, 1/4, 1/20]", Decomp.Decompose("4", "5")); }
public void Test_Decomp_Juliet() { Assert.AreEqual("[1/2, 1/7, 1/59, 1/5163, 1/53307975]", Decomp.Decompose("66", "100")); }
public void Test_Decomp_Kilo() { Assert.AreEqual("[1/2, 1/3, 1/9, 1/83, 1/34362]", Decomp.Decompose("22", "23")); }
public void Test_Decomp_Lima() { Assert.AreEqual("[1/5]", Decomp.Decompose("7", "35")); }
public void Test_Decomp_Mike() { Assert.AreEqual("[1, 1/2]", Decomp.Decompose("45", "30")); }
public void Test_Decomp_Bravo() { Assert.AreEqual("[1, 1/4]", Decomp.Decompose("125", "100")); }
public void Test_Decomp_Charlie() { Assert.AreEqual("[1/4, 1/26, 1/848, 1/2381184]", Decomp.Decompose("1001", "3456")); }
public static void test(string numerator, string denominator, string exceptedResult) { testing(Decomp.Decompose(numerator, denominator), exceptedResult); }
public void Test_Decomp_Hotel() { Assert.AreEqual("[1/2, 1/3, 1/13, 1/359, 1/644046]", Decomp.Decompose("21", "23")); }
public void Test_Decomp_Golf() { Assert.AreEqual("[1/2, 1/3, 1/15]", Decomp.Decompose("9", "10")); }
public void Test_Decomp_Foxtrot() { Assert.AreEqual("[]", Decomp.Decompose("0", "2")); }
public void Test_Decomp_Echo() { Assert.AreEqual("[3]", Decomp.Decompose("12", "4")); }
public void Test_Decomp_Delta() { Assert.AreEqual("[1/2, 1/4]", Decomp.Decompose("3", "4")); }
/// <summary> /// This decomposites the provided ground chunk, supporting holes too. /// This will convert the ground chunk into a Polygon object that is then /// passed to the Poly2Tri library which returns the triangle arrays of /// decomposition. /// </summary> /// <param name="chunk"></param> private void Decomp(GroundChunk chunk) { List <PolygonPoint> edge = new List <PolygonPoint>(); for (int i = 0; i < chunk.Edge.Count; i++) { edge.Add(new PolygonPoint(chunk.Edge[i].x, chunk.Edge[i].y)); } List <Polygon> holes = new List <Polygon>(); if (chunk.Holes != null) { for (int i = 0; i < chunk.Holes.Count; i++) { List <PolygonPoint> hole = new List <PolygonPoint>(); for (int j = 0; j < chunk.Holes[i].Count; j++) { hole.Add(new PolygonPoint(chunk.Holes[i][j].x, chunk.Holes[i][j].y)); } holes.Add(new Polygon(hole)); } } Polygon poly = new Polygon(edge); for (int i = 0; i < holes.Count; i++) { poly.AddHole(holes[i]); } //Triangulate! P2T.Triangulate(poly); IList <TriangulationPoint> points = poly.Points; IList <DelaunayTriangle> tris = poly.Triangles; List <Vector2> finalPoints = new List <Vector2>(); int[] finalTris = new int[tris.Count * 3]; Dictionary <TriangulationPoint, int> pointToIndex = new Dictionary <TriangulationPoint, int>(); for (int t = 0; t < tris.Count; t++) { DelaunayTriangle tri = tris[t]; for (int i = 0; i < 3; i++) { //check if the points are in the dictionary, if not add it with the next index int val = 0; if (pointToIndex.TryGetValue(tri.Points[i], out val)) { finalTris[t * 3 + i] = val; } else { finalPoints.Add(new Vector2() { x = tri.Points[i].Xf, y = tri.Points[i].Yf }); pointToIndex[tri.Points[i]] = finalPoints.Count - 1; finalTris[t * 3 + i] = finalPoints.Count - 1; } } } Decomp result = new Decomp(); result.Points = finalPoints; result.Tris = finalTris; chunk.Poly = result; }
public void Test_Decomp_Alpha() { Assert.AreEqual("[1]", Decomp.Decompose("4", "4")); }