Esempio n. 1
0
        public void CreateInterpolator_ReturnsFunctionWhichEvaluatesToInputs()
        {
            var xCoords = new[] { 1.2, 1.8, 2.5, 8.65 };
            var yCoords = new[] { 46.56, -1.58, 8.556, 12.65 };

            var interpolatorFactor = new NaturalCubicSplineInterpolatorFactory();

            Func <double, double> interpolator = interpolatorFactor.CreateInterpolator(xCoords, yCoords);

            for (int i = 0; i < xCoords.Length; i++)
            {
                double x         = xCoords[i];
                double y         = interpolator(x);
                double expectedY = yCoords[i];
                Assert.Equal(expectedY, y, 12);
            }
        }
Esempio n. 2
0
        public void CreateInterpolator_FlatInputs_ReturnsFunctionWhichEvaluatesToConstantYValue()
        {
            const double constantY = 15.85;
            var          xCoords   = new[] { 1.2, 1.8, 2.5, 8.65 };
            var          yCoords   = new[] { constantY, constantY, constantY, constantY };

            var interpolatorFactor = new NaturalCubicSplineInterpolatorFactory();

            Func <double, double> interpolator = interpolatorFactor.CreateInterpolator(xCoords, yCoords);

            var xsToEvaluate = new[] { 1.36, 2.15, 5.68, 7.99 };

            foreach (double x in xsToEvaluate)
            {
                double y = interpolator(x);
                Assert.Equal(constantY, y);
            }
        }