Skip to content

Commit

Permalink
test large number
Browse files Browse the repository at this point in the history
  • Loading branch information
e-silvestri committed Jan 3, 2022
1 parent ae1305e commit bf18276
Show file tree
Hide file tree
Showing 4 changed files with 1,176 additions and 1,140 deletions.
39 changes: 34 additions & 5 deletions PtVzzlexMasCake.Tests/PuzzleSolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ public void PuzzleSolverTest()
}
}

[TestMethod]
[DataRow(10)]
[DataRow(100)]
[DataRow(1000)]
[DataRow(10000)]
public void SolveBigNumber(int digits)
{
var r = new Random(0);
var s = new char[digits];
for (int i = 0; i < digits; i++)
{
s[i] = r.Next(10).ToString().First();
}
var value = BigInteger.Parse(new string(s));
var solution = PuzzleSolver.Solve(value);
var initialValue = value;
foreach (var operation in solution)
{
initialValue = Operator.Execute(operation, initialValue);
}
Assert.AreEqual(1, initialValue);
}

[TestMethod]
public void FindAllSolutions()
{
Expand All @@ -81,7 +104,10 @@ public void FindAllSolutions()
var interestingNodes = result; // result.Where(x => x.Value.Count == 1);
foreach (var item in interestingNodes)
{
drawingGraph.AddNode(item.Key.ToString()).LabelText = item.Key.ToString();
var node = new Microsoft.Msagl.Drawing.Node(item.Key.ToString());
node.LabelText = item.Key.ToString();
node.Label.FontColor = item.Key.IsEven ? Color.DarkGreen : Color.Red;
drawingGraph.AddNode(node);
}
foreach (var item in interestingNodes)
{
Expand All @@ -106,7 +132,8 @@ public void FindAllSolutions()
{
// Ideally we should look at the drawing node attributes, and figure out, the required node size
// I am not sure how to find out the size of a string rendered in SVG. Here, we just blindly assign to each node a rectangle with width 60 and height 40, and round its corners.
n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(60, 40, 3, 2, new Point(0, 0));
n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(40, 40, 5, 5, new Point(0, 0)); // .CreateCircle(20, new Point(0, 0)); //

}

AssignLabelsDimensions(drawingGraph);
Expand All @@ -119,16 +146,17 @@ static void AssignLabelsDimensions(Graph drawingGraph)
// In general, the label dimensions should depend on the viewer
foreach (var na in drawingGraph.Nodes)
{
na.Label.Width = na.Width * 0.6;
na.Label.Width = 40;
na.Label.Height = 40;
}

// init geometry labels as well
foreach (var de in drawingGraph.Edges)
{
// again setting the dimensions, that should depend on Drawing.Label and the viewer, blindly
de.Label.GeometryLabel.Width = 140;
de.Label.GeometryLabel.Height = 60;
de.Label.GeometryLabel.Width = 40;
de.Label.GeometryLabel.Height = 40;

}
}

Expand All @@ -146,4 +174,5 @@ static void PrintSvgAsString(Graph drawingGraph)
sw.Write(myStr);
}
}

}
19 changes: 17 additions & 2 deletions PtVzzlexMasCake/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@

public static class Runner
{
public static string FileName { get; set; } = "output.txt";
public static string FileName { get; set; } = "output.txt";
const int digits = 1000;
public static void Run(string[] args)
{
var value = BigInteger.Parse(args[0]);
BigInteger value = 512;
if (args.Length == 1)
{
value = BigInteger.Parse(args[0]);
}
else
{
var r = new Random();
var s = new char[digits];
for (int i = 0; i < digits; i++)
{
s[i] = r.Next(10).ToString().First();
}
value = BigInteger.Parse(new string(s));
}
var solution = PuzzleSolver.Solve(value);
using var sw = new StreamWriter(FileName);
sw.WriteLine(value.ToString());
Expand Down
8 changes: 0 additions & 8 deletions PtVzzlexMasCake/Properties/launchSettings.json

This file was deleted.

Loading

0 comments on commit bf18276

Please sign in to comment.