1   /* Copyright 2022-2025 Romain Serra
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
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  package org.orekit.control.indirect.adjoint.cost;
18  
19  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
20  import org.hipparchus.util.Binary64;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  import org.junit.jupiter.params.ParameterizedTest;
24  import org.junit.jupiter.params.provider.ValueSource;
25  import org.orekit.errors.OrekitException;
26  import org.orekit.errors.OrekitMessages;
27  
28  class FieldPenalizedCartesianFuelCostTest {
29  
30      @ParameterizedTest
31      @ValueSource(doubles = {-2, 2})
32      void testExceptionConstructor(final double epsilon) {
33          // GIVEN
34          final Binary64 magnitude = Binary64.ONE;        // WHEN & THEN
35          final Binary64 outOfBoundsEpsilon = magnitude.newInstance(epsilon);
36          final OrekitException exception = Assertions.assertThrows(OrekitException.class,
37                  () -> new TestPenalizedCost(magnitude, outOfBoundsEpsilon));
38          Assertions.assertEquals(OrekitMessages.INVALID_PARAMETER_RANGE, exception.getSpecifier());
39      }
40  
41      @Test
42      void testGetters() {
43          // GIVEN
44          final Binary64 expectedMagnitude = Binary64.ONE;
45          final Binary64 expectedEpsilon = Binary64.ZERO;
46          // WHEN
47          final TestPenalizedCost penalizedCost = new TestPenalizedCost(expectedMagnitude, expectedEpsilon);
48          // THEN
49          Assertions.assertEquals(expectedEpsilon, penalizedCost.getEpsilon());
50          Assertions.assertEquals(expectedMagnitude, penalizedCost.getMaximumThrustMagnitude());
51      }
52  
53      private static class TestPenalizedCost extends FieldPenalizedCartesianFuelCost<Binary64> {
54  
55          protected TestPenalizedCost(Binary64 maximumThrustMagnitude, Binary64 epsilon) {
56              super("", Binary64.ZERO, maximumThrustMagnitude, epsilon);
57          }
58  
59          @Override
60          public Binary64 evaluateFieldPenaltyFunction(Binary64 controlNorm) {
61              return Binary64.ZERO;
62          }
63  
64          @Override
65          public FieldVector3D<Binary64> getFieldThrustAccelerationVector(Binary64[] adjointVariables, Binary64 mass) {
66              return null;
67          }
68  
69          @Override
70          public void updateFieldAdjointDerivatives(Binary64[] adjointVariables, Binary64 mass, Binary64[] adjointDerivatives) {
71              // not used
72          }
73  
74          @Override
75          public CartesianCost toCartesianCost() {
76              return null;
77          }
78      }
79  }