private Matrix <Cell> PerformCellAndSegmentCalculation() { Matrix <Cell> matrix = CellCalculator.Calculate(Board, Board.TopLeft.X, Board.BottomRight.X); SegmentCalculator.Calculate(matrix); return(matrix); }
private Matrix <SegmentState> GetSegmentStateMatrixUsingCellMatrix(Axis axisOfMovement) { Matrix <SegmentState> segStateMatrix = SegmentCalculator.GetBoardSegmentStateMatrixForAxisOfMovement( CellMatrix, Board, axisOfMovement); return(segStateMatrix); }
public void GivenMessage_GetSegments(string message, int expectedSegments, Charset expectedCharset) { if (message == "hello world") { Debugger.Break(); } var segmentCalc = new SegmentCalculator(); (var actualSegments, var actualCharset) = segmentCalc.GetSegmentsCount(message); Assert.AreEqual(expectedSegments, actualSegments, $"Expected {expectedSegments} but got {actualSegments}."); Assert.AreEqual(expectedCharset, actualCharset, $"Expected {expectedCharset} but got character set {actualCharset}"); }
public void Test(int repetitions, int smallRepetitions, string logFilePath) { VerticalSegmentStateMatrix = PerformanceTestHelper.TimeFunction(logFilePath, "Test calculation of vertical segment state matrix directly from the BitMatrix", repetitions, GetVerticalSegmentStateMatrix); // Save image for vertical segment state matrix: Bitmap segStateBitmap = ImageGenerator.GenerateBoardImage(Board); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical); string segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\VertSegmentMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); HorizontalSegStateMatrix = PerformanceTestHelper.TimeFunction(logFilePath, "Test calculation of horizontal segment state matrix directly from the BitMatrix", repetitions, GetHorizontalSegmentStateMatrix); // Save image for horizontal segment state matrix: segStateBitmap = ImageGenerator.GenerateBoardImage(Board); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, HorizontalSegStateMatrix, Axis.Horizontal); segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\HorizSegmentMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical); segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\BiDiSegmentMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); // Test calculation caches: PerformanceTestHelper.TimeAction(logFilePath, "Time cell calculator on challenge board 1", smallRepetitions, PerformCellCalculation); CellMatrix = PerformanceTestHelper.TimeFunction(logFilePath, "Time cell and segment calculator on challenge board 1", smallRepetitions, PerformCellAndSegmentCalculation); // Repeat segment stage calculations using implementation based on pre-calculated cell and segment calculations: VerticalSegmentStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test calculation of vertical segment state matrix using a cell matrix", repetitions, Axis.Vertical, GetSegmentStateMatrixUsingCellMatrix); // Save image for vertical segment state matrix: segStateBitmap = ImageGenerator.GenerateBoardImage(Board); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical); segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\VertSegmentMatrixUsingCellMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); HorizontalSegStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test calculation of horizontal segment state matrix using a cell matrix", repetitions, Axis.Horizontal, GetSegmentStateMatrixUsingCellMatrix); // Repeat segment state calculation using Segment matrix calculated from the Cell matrix: Matrix <Segment> vertSegmentMatrix = SegmentCalculator.GetSegmentMatrix(CellMatrix, Board, Axis.Vertical); VerticalSegmentStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test calculation of vertical segment state matrix using a segment matrix", repetitions, Tuple.Create(vertSegmentMatrix, Board), (tuple) => SegmentCalculator.GetBoardSegmentStateMatrixFromSegmentMatrix(tuple.Item1, tuple.Item2)); Matrix <Segment> horizSegmentMatrix = SegmentCalculator.GetSegmentMatrix(CellMatrix, Board, Axis.Horizontal); HorizontalSegStateMatrix = PerformanceTestHelper.TimeFunctionWithArgument(logFilePath, "Test calculation of vertical segment state matrix using a segment matrix", repetitions, Tuple.Create(horizSegmentMatrix, Board), (tuple) => SegmentCalculator.GetBoardSegmentStateMatrixFromSegmentMatrix(tuple.Item1, tuple.Item2)); // Save image for horizontal segment state matrix: segStateBitmap = ImageGenerator.GenerateBoardImage(Board); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, HorizontalSegStateMatrix, Axis.Horizontal); segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\HorizSegmentMatrixUsingCellMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); ImageGenerator.DrawSegmentMatrixOverlay(segStateBitmap, Board, VerticalSegmentStateMatrix, Axis.Vertical); segmentMatrixFilePath = @"c:\Competitions\EntelectChallenge2013\temp\BiDiSegmentMatrixUsingCellMatrix.bmp"; segStateBitmap.Save(segmentMatrixFilePath, ImageFormat.Bmp); }