static void Main(string[] args) { Console.WriteLine("Application Starts..."); Console.WriteLine("Ready For Input"); Console.WriteLine("Example Input:"); Console.WriteLine("4 (commands)"); Console.WriteLine("10 10 (start position)"); Console.WriteLine("W 10 (west 10)"); Console.WriteLine("N 4 (north 4)"); Console.WriteLine("E 14 (east 14)"); Console.WriteLine("5 20 (south 20)"); RobotsCommands commandFactory = new RobotsCommands(); while (!commandFactory.InputsCompleated) { // Adding Robot Inputs commandFactory.AddInput(Console.ReadLine()); } Console.WriteLine("Robot Instructions are complete."); Console.ReadLine(); // robot executing input commands SimpleReporter jobReporter = new SimpleReporter(); CleanerRobot cleanerRobot = new CleanerRobot(commandFactory.GetCommandSet(), jobReporter, new Location(0, 0), new Location(12, 12)); cleanerRobot.Run(); //give output on the number of places cleaned Console.WriteLine(cleanerRobot.PrintReport()); }
public void RunRobot_SomeCasesAndManyCases_NLogNPerformance() { SimpleReporter reporter = new SimpleReporter(); //Arrange Location currentPosition = new Location(0, 0); var timer = Stopwatch.StartNew(); for (int i = 1; i < 2300; i++) { currentPosition = new Location(currentPosition.X, currentPosition.Y + 1); reporter.RegisterNewPosition(currentPosition); } timer.Stop(); var elapsedTime23Cases = timer.Elapsed; //Act timer = Stopwatch.StartNew(); for (int i = 1; i < 9200; i++) { currentPosition = new Location(currentPosition.X, currentPosition.Y + 1); reporter.RegisterNewPosition(currentPosition); } timer.Stop(); var elapsedTime92Cases = timer.Elapsed; //Assert Assert.IsTrue(elapsedTime92Cases.Milliseconds < (elapsedTime23Cases.Milliseconds * 8), elapsedTime92Cases.Milliseconds + "vs" + (elapsedTime23Cases.Milliseconds * 8)); }
public void Reporter_CaseExecPerformance() { SimpleReporter simpleReporter = new SimpleReporter(); Location currentPosition = new Location(0, 0); var timer = Stopwatch.StartNew(); //2300 Cases for (int i = 0; i < 2300; i++) { currentPosition = new Location(currentPosition.X, currentPosition.Y + 1); simpleReporter.RegisterNewPosition(currentPosition); } timer.Stop(); var elapsedTimeSet1 = timer.Elapsed; timer = Stopwatch.StartNew(); //9200 Cases for (int i = 0; i < 9200; i++) { currentPosition = new Location(currentPosition.X, currentPosition.Y + 1); simpleReporter.RegisterNewPosition(currentPosition); } timer.Stop(); var elapsedTimeSet2 = timer.Elapsed; Assert.IsTrue(elapsedTimeSet2.Milliseconds <= elapsedTimeSet1.Milliseconds * 30, elapsedTimeSet2.Milliseconds + " Vs " + elapsedTimeSet1.Milliseconds * 30); }
public void SampleReportIsGenerated() { var refs = new Analyzer().ProcessCSharpClasses(@"using Apex.System; namespace ApexTest { class Program { static void Main(string[] args) { var map = new Map<int, string>(); map.put(1, ""Hello""); var json = JSON.serializePretty(map); var length = json.Length; var ignored = ""JSON.deserialize(json)""; // ignored: map.get(1); RestContext.response = null; } } }"); CompareLineByLine(SimpleReporter.GetReport(refs.Values), @"Apex.System JSON serializePretty(object) Map new Map(...) put(...) RestContext response"); }
public void GetReferenceReportFromZippedLibrary() { var files = GetApexClassesFromZipFile("apex-lambda-master").ToArray(); var refs = new Analyzer().ProcessApexClasses(files); Assert.NotNull(refs); Assert.AreEqual(14, refs.Count); CompareLineByLine(SimpleReporter.GetReport(refs.Values), @"Apex.Schema SObjectType newSObject() Apex.System Date newInstance(int, int, int) Datetime newInstance(int, int, int) ID List new List(...) add(...) addAll(...) clear() iterator() size() Map new Map(...) containsKey(...) get(...) keySet() put(...) size() Math abs(double) NoSuchElementException new NoSuchElementException() Set new Set(...) add(...) contains(...) size() SObject get(Apex.Schema.SObjectField) get(string) getPopulatedFieldsAsMap() getSObjectType() put(string, object) Id StringExtensions string.length() System assert(bool) assert(bool, object) assertEquals(object, object) assertEquals(object, object, object) Time newInstance(int, int, int, int) Type newInstance()"); }
static void Main(string[] args) { //Get input commands CommandFactory commandFactory = new CommandFactory(); Console.WriteLine("Enter Inputs:"); while (!commandFactory.IsInputComplete) { Console.WriteLine(">"); commandFactory.AddInputs(Console.ReadLine()); } Console.WriteLine("Input Complete, Press any key to continue.."); Console.ReadLine(); //Execute commands SimpleReporter reporter = new SimpleReporter(); Robot robo = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0, 0), new Location(10, 10)); robo.ExecuteCommands(); //Reports number of places cleaned Console.WriteLine(reporter.ReportOutPut()); Console.ReadLine(); }
public void RobotCleanerReport() { RobotsCommands сommandFactory = new RobotsCommands(); сommandFactory.AddInput("4"); сommandFactory.AddInput("0 0"); сommandFactory.AddInput("N 10"); сommandFactory.AddInput("E 10"); сommandFactory.AddInput("S 10"); сommandFactory.AddInput("W 10"); Commands commandSet = сommandFactory.GetCommandSet(); // creating the report IReport testReporter = new SimpleReporter(); // creating the robot CleanerRobot cleanerRobot = new CleanerRobot(commandSet, testReporter); // moving the robot cleanerRobot.Run(); // gethering the report string whereHaveYouBeen = cleanerRobot.PrintReport(); // Assert.AreEqual("=> Cleaned: 0", whereHaveYouBeen); // We are doing complete loop // And Robot comming back to 0 0 Assert.AreEqual("=> Cleaned: 40", whereHaveYouBeen); Assert.AreEqual(commandSet.startPosition.x, cleanerRobot.location.x); Assert.AreEqual(commandSet.startPosition.y, cleanerRobot.location.y); }
public void GetNotImplementedReportForDirectoryWithApexClasses() { var refs = new Analyzer().ProcessDirectories("."); Assert.NotNull(refs); Assert.AreEqual(18, refs.Count); CompareLineByLine(SimpleReporter.GetReport(refs.Values, notImplementedOnly: true), @"Apex.System ApexPages addMessages(Apex.System.Exception) SelectOption new SelectOption(string, string)"); }
private static SampleStatistics[] BronKerboschTimed(RandomUndirectedGraph graph, int[] funcIndices, int samples) { List <ImmutableArray <Vertex> >?first = null; SampleStatistics[] times = Enumerable.Range(0, Portfolio.FuncNames.Length) .Select(funcIndex => new SampleStatistics()).ToArray(); for (var sample = samples == 1 ? 1 : 0; sample <= samples; ++sample) { foreach (var funcIndex in funcIndices) { if (sample == 0) { var reporter = new SimpleReporter(); var sw = Stopwatch.StartNew(); Portfolio.Explore(funcIndex, graph.Graph, reporter); sw.Stop(); var secs = sw.ElapsedMilliseconds / 1e3; if (secs >= 3.0) { Console.WriteLine($" {Portfolio.FuncNames[funcIndex],8}: {secs,6:N2}s"); } Portfolio.SortCliques(reporter.Cliques); if (first == null) { if (reporter.Cliques.Count != graph.CliqueCount) { throw new ArgumentException( $"Expected {graph.CliqueCount} cliques, got {reporter.Cliques.Count}"); } first = reporter.Cliques; } else { Portfolio.AssertSameCliques(first, reporter.Cliques); } } else { var reporter = new CountingReporter(); var sw = Stopwatch.StartNew(); Portfolio.Explore(funcIndex, graph.Graph, reporter); sw.Stop(); var secs = sw.ElapsedMilliseconds / 1e3; times[funcIndex].Put(secs); } } } return(times); }
public void RunRobot_SimpleCommandSet_RobotPositionYShouldChangeBy1() { //arrange CommandFactory commandFactory = new CommandFactory(); commandFactory.AddInput("1"); commandFactory.AddInput("0 0"); commandFactory.AddInput("N 1"); CommandSet commandSet = commandFactory.GetCommandSet(); IReport reporter = new SimpleReporter(); Robot robot = new Robot(commandSet, reporter); //act robot.ExecuteCommands(); //assert Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X); Assert.AreEqual(commandSet.StartPosition.Y + 1, robot.Position.Y); }
public void RunRobot_SimpleCommandSetReportLocationCleaned() { CommandFactory commandFactory = new CommandFactory(); commandFactory.AddInputs("1"); commandFactory.AddInputs("20 20"); commandFactory.AddInputs("N 1"); CommandSet commandSet = commandFactory.GetCommandSet(); IReport reporter = new SimpleReporter(); Robot robot = new Robot(commandSet, reporter, new Location(-100000, -100000), new Location(100000, 100000)); robot.ExecuteCommands(); string report = robot.ReportOutPut(); Assert.AreEqual("=> Cleaned: 1", report); }
private static void Bk(int[][] adjacencies, int[][] cliques) { var adjacencies2 = adjacencies.Select(neighbours => neighbours.Select(i => Vertex.Nth(i)).ToHashSet()) .ToImmutableArray(); var cliques2 = cliques.Select(clique => clique.Select(i => Vertex.Nth(i)).ToArray()).ToArray(); var graph = new UndirectedGraph(adjacencies2); foreach (var funcIndex in Enumerable.Range(0, Portfolio.FuncNames.Length)) { var reporter = new SimpleReporter(); Portfolio.Explore(funcIndex, graph, reporter); Assert.AreEqual(cliques2.Length, reporter.Cliques.Count); Portfolio.SortCliques(reporter.Cliques); foreach ((var reportedClique, var i) in reporter.Cliques.Select((v, i) => (v, i))) { Assert.That(reportedClique.SequenceEqual(cliques2[i])); } } }
public void GetReferencesForListMapAndSetClasses() { var refs = new Analyzer().ProcessCSharpClasses(@"using Apex.System; namespace ApexTest { class Program { static void Main(string[] args) { var map = new Map<int, string>(); map.put(1, ""Hello""); var map2 = new Map<string, int>; map.put(""World"", 123); var list1 = new List<string>(); list1.add(""Hi""); var list2 = new List<int>(); list2.add(123); var set = new Set<int>(); var set2 = new Set<string>(list1); var set3 = map2.keySet(); set3.add(""There""); } } }"); CompareLineByLine(SimpleReporter.GetReport(refs.Values), @"Apex.System List new List(...) add(...) Map new Map(...) keySet() put(...) Set new Set(...) add(...)"); }
public void RunRobot_SimplestCommandSetOneMove_RobotReports1LocationCleaned() { //arrange CommandFactory commandFactory = new CommandFactory(); commandFactory.AddInput("1"); commandFactory.AddInput("10 10"); commandFactory.AddInput("N 1"); CommandSet commandSet = commandFactory.GetCommandSet(); IReport reporter = new SimpleReporter(); Robot robot = new Robot(commandSet, reporter, new Location(-100000, -100000), new Location(100000, 100000)); robot.ExecuteCommands(); //act string report = robot.PrintReport(); //assert Assert.AreEqual("=> Cleaned: 1", report); }
public void RunRobot_BoxMoveCommandSet_NumberofLocationsIsCorrect() { //arrange CommandFactory commandFactory = new CommandFactory(); commandFactory.AddInput("4"); commandFactory.AddInput("0 0"); commandFactory.AddInput("N 7"); commandFactory.AddInput("E 7"); commandFactory.AddInput("S 7"); commandFactory.AddInput("W 7"); CommandSet commandSet = commandFactory.GetCommandSet(); IReport reporter = new SimpleReporter(); Robot robot = new Robot(commandSet, reporter, new Location(0, 0), new Location(7, 7)); //act robot.ExecuteCommands(); string report = robot.PrintReport(); //assert Assert.AreEqual("=> Cleaned: 28", report); }
static void Main(string[] args) { //collect a set of inputs from standard in CommandFactory commandFactory = new CommandFactory(); while (!commandFactory.InputsAreComplete) { Console.WriteLine(">"); commandFactory.AddInput(Console.ReadLine()); } Console.WriteLine("Input complete. Press any key to continue.."); Console.ReadLine(); //robot should execute cleaning commands SimpleReporter reporter = new SimpleReporter(); Robot robbie = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0,0), new Location(7,7)); robbie.ExecuteCommands(); //give output on the number of places cleaned Console.WriteLine(robbie.PrintReport()); }
static void Main(string[] args) { //accept a set of input from standard in CommandFactory commandFactory = new CommandFactory(); while (!commandFactory.InputsAreComplete) { Console.WriteLine(">"); commandFactory.AddInput(Console.ReadLine()); } Console.WriteLine("Input is Complete. Press any key to continue"); Console.ReadLine(); //robot cleaner should execute cleaning commands SimpleReporter repoter = new SimpleReporter(); Robot vacuum = new Robot(commandFactory.GetCommandSet(), repoter, new Location(0, 0), new Location(7, 7)); vacuum.ExecuteCommands(); //robot cleaner should output the number of places cleaned Console.WriteLine(vacuum.PrintReport()); }
static void Main(string[] args) { //collect a set of inputs from standard in CommandFactory commandFactory = new CommandFactory(); while (!commandFactory.InputsAreComplete) { Console.WriteLine(">"); commandFactory.AddInput(Console.ReadLine()); } Console.WriteLine("Input complete. Press any key to continue.."); Console.ReadLine(); //robot should execute cleaning commands SimpleReporter reporter = new SimpleReporter(); Robot robbie = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0, 0), new Location(7, 7)); robbie.ExecuteCommands(); //give output on the number of places cleaned Console.WriteLine(robbie.PrintReport()); }
public void RunRobot_CommandSetWithLocationMovements() { CommandFactory commandFactory = new CommandFactory(); commandFactory.AddInputs("4"); commandFactory.AddInputs("0 0"); commandFactory.AddInputs("N 5"); commandFactory.AddInputs("E 5"); commandFactory.AddInputs("S 5"); commandFactory.AddInputs("W 5"); CommandSet commandSet = commandFactory.GetCommandSet(); IReport reporter = new SimpleReporter(); Robot robot = new Robot(commandSet, reporter, new Location(0, 0), new Location(5, 5)); robot.ExecuteCommands(); string report = robot.ReportOutPut(); Assert.AreEqual("=> Cleaned: 20", report); }
public void GetReportForDirectoryWithApexClasses() { var refs = new Analyzer().ProcessDirectories("."); Assert.NotNull(refs); Assert.AreEqual(18, refs.Count); CompareLineByLine(SimpleReporter.GetReport(refs.Values), @"Apex.System ApexPages addMessages(Apex.System.Exception) Blob toString() valueOf(string) Date today() Exception getMessage() JSON deserialize(string, Apex.System.Type) serialize(object) List new List(...) add(...) clear() get(int) isEmpty() set(int, int) size() sort() Map new Map(...) get(...) keySet() put(...) Math random() round(double) MathException new MathException(string) RestContext request response RestRequest new RestRequest() requestBody RestResponse new RestResponse() statusCode SelectOption new SelectOption(string, string) Set new Set(...) add(...) remove(int) StringExtensions string.length() System assert(bool) assert(bool, object) assertEquals(object, object) assertEquals(object, object, object) assertNotEquals(object, object, object) debug(object) runAs(Apex.System.Version) Time newInstance(int, int, int, int)"); }