public async Task Square() { const double sideLength = 20d; var shape = new SquarePolygonGenerator().Generate(sideLength); var mc = new MonteCarloAreaCalculator(); var area = await mc.CalculateAreaAsync(shape); Assert.Equal(Math.Pow(sideLength, 2), area); }
public async Task ProgressIterations() { const double sideLength = 20d; var shape = new SquarePolygonGenerator().Generate(sideLength); var mc = new MonteCarloAreaCalculator(new MonteCarloAreaCalculator.Options { Iterations = 10, ProgressReportingIterations = 2 }); var progresses = new List <double>(); var progressMock = new Mock <IProgress <AreaCalculationProgress> >(); progressMock.Setup(x => x.Report(It.IsAny <AreaCalculationProgress>())) .Callback <AreaCalculationProgress>((progress) => progresses.Add(progress.ProgressPercentage)); await mc.CalculateAreaAsync(shape, CancellationToken.None, progressMock.Object); Assert.Equal(new[] { 0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d }, progresses); }
public async Task ProgressTime() { const double sideLength = 20d; var shape = new SquarePolygonGenerator().Generate(sideLength); var mc = new MonteCarloAreaCalculator(new MonteCarloAreaCalculator.Options { SimulationDuration = TimeSpan.FromMilliseconds(50), ProgressReportingIterations = 2 }); var progresses = new List <double>(); var progressMock = new Mock <IProgress <AreaCalculationProgress> >(); progressMock.Setup(x => x.Report(It.IsAny <AreaCalculationProgress>())) .Callback <AreaCalculationProgress>((progress) => progresses.Add(progress.ProgressPercentage)); await mc.CalculateAreaAsync(shape, CancellationToken.None, progressMock.Object); Assert.True(progresses.Count > 2); Assert.Equal(0d, progresses[0]); Assert.Equal(1d, progresses[progresses.Count - 1]); }
public async Task ProgressIterations() { const double sideLength = 20d; var shape = new SquarePolygonGenerator().Generate(sideLength); var mc = new MonteCarloAreaCalculator(new MonteCarloAreaCalculatorOptions { Iterations = 10, ProgressReportingIterations = 2 }); // Note use of Mocking framework var progresses = new List <double>(5); var progressMock = new Mock <IProgress <double> >(); progressMock.Setup(x => x.Report(It.IsAny <double>())) .Callback((double progress) => progresses.Add(progress)); await mc.CalculateAreaAsync(shape, progressMock.Object, CancellationToken.None) .ConfigureAwait(false); Assert.Equal(new[] { 0d, 0.2d, 0.4d, 0.6d, 0.8d, 1d }, progresses); }
public void SquareToMarkup() { var square = new SquarePolygonGenerator().Generate(10d); Assert.Equal("M0,0L10,0L10,10L0,10Z", PathMarkupConverter.Convert(square)); }