|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | + |
| 19 | +#include "itkCompositeValleyFunction.h" |
| 20 | +#include "itkMath.h" |
| 21 | +#include <gtest/gtest.h> |
| 22 | + |
| 23 | +TEST(CompositeValleyFunction, BoundsAndInterval) |
| 24 | +{ |
| 25 | + itk::Array<double> means(2); |
| 26 | + itk::Array<double> sigmas(2); |
| 27 | + |
| 28 | + means[0] = 0.0; |
| 29 | + means[1] = 100.0; |
| 30 | + sigmas[0] = 20.0; |
| 31 | + sigmas[1] = 20.0; |
| 32 | + |
| 33 | + itk::CompositeValleyFunction function(means, sigmas); |
| 34 | + |
| 35 | + EXPECT_DOUBLE_EQ(function.GetUpperBound(), 280.0); |
| 36 | + EXPECT_DOUBLE_EQ(function.GetLowerBound(), -180.0); |
| 37 | + |
| 38 | + const double interval1 = function.GetInterval(); |
| 39 | + const double interval2 = (function.GetUpperBound() - function.GetLowerBound()) / (1000000.0 - 1.0); |
| 40 | + EXPECT_NEAR(interval1, interval2, itk::NumericTraits<double>::epsilon()); |
| 41 | +} |
| 42 | + |
| 43 | +TEST(CompositeValleyFunction, EvaluateMatchesCallOperator) |
| 44 | +{ |
| 45 | + itk::Array<double> means(2); |
| 46 | + itk::Array<double> sigmas(2); |
| 47 | + |
| 48 | + means[0] = 0.0; |
| 49 | + means[1] = 100.0; |
| 50 | + sigmas[0] = 20.0; |
| 51 | + sigmas[1] = 20.0; |
| 52 | + |
| 53 | + itk::CompositeValleyFunction function(means, sigmas); |
| 54 | + |
| 55 | + const long numberOfSamples = function.GetNumberOfSamples(); |
| 56 | + const double measure = function.GetLowerBound() + function.GetInterval() * numberOfSamples * 0.5; |
| 57 | + const double value1 = function(measure); |
| 58 | + const double value2 = function.Evaluate(measure); |
| 59 | + |
| 60 | + EXPECT_NEAR(value1, value2, itk::NumericTraits<double>::epsilon()); |
| 61 | +} |
0 commit comments