public void When_DrawFunctionPlotWithConstantFunction_ShouldDrawFunctionPlot()
        {
            //Arrange
            const int width  = 800;
            const int height = 600;

            var yValue = Math.Round(1d, 2);
            var maxY   = (yValue + _functionPlotterViewModel.MaxY).ToString(CultureInfo.InvariantCulture);
            var minY   = (yValue + _functionPlotterViewModel.MinY).ToString(CultureInfo.InvariantCulture);

            var functionPoints = new List <PointF>
            {
                new PointF(-1, 1),
                new PointF(0, 1),
                new PointF(1, 1)
            };
            var integralRectangles = new List <(PointF, PointF)>
            {
                (new PointF(-1, 1), new PointF(0, 0)),
                (new PointF(0, 1), new PointF(1, 0))
            };

            _painterMock.Setup(x => x.DrawAxis(It.IsAny <int>()));
            _painterMock.Setup(x => x.DrawFunction(It.IsAny <List <PointF> >()));
            _painterMock.Setup(x => x.ResetTransform());
            _painterMock.Setup(x => x.DrawString(It.IsAny <PointF>(), It.IsAny <string>(), It.IsAny <int>()));

            _functionMock
            .Setup(x => x.GetFunctionGraph(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <double>()))
            .Returns(functionPoints);

            //Act
            _functionPlotter.DrawFunctionPlot(width, height);

            //Assert
            const int twice = 2;

            _painterMock.Verify(x => x.DrawAxis(It.IsAny <int>()), Times.Once);
            _painterMock.Verify(x => x.DrawFunction(It.IsAny <List <PointF> >()), Times.Once);
            _painterMock.Verify(x => x.ResetTransform(), Times.Exactly(twice));
            _painterMock.Verify(x => x.DrawString(It.IsAny <PointF>(), minY, It.IsAny <int>()), Times.Once);
            _painterMock.Verify(x => x.DrawString(It.IsAny <PointF>(), maxY, It.IsAny <int>()), Times.Once);
        }
Beispiel #2
0
        public void Draw(int width, int height)
        {
            Ensure.Arg(width)
            .IsGreaterThan(0);

            Ensure.Arg(height)
            .IsGreaterThan(0);

            if (PlotterViewModel.DrawIntegral)
            {
                _plotter.DrawIntegralFunctionPlot(width, height);
            }
            else
            {
                _plotter.DrawFunctionPlot(width, height);
            }

            FunctionImage.Source = _plotter.GetFunctionImage();

            Ensure.Arg(FunctionImage.Source).IsNotNull();
        }