File size: 7,796 Bytes
5ab75a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
classdef (SharedTestFixtures = { ...
        matlab.unittest.fixtures.PathFixture('..') ...
        matlab.unittest.fixtures.PathFixture('../Utils') ...
        matlab.unittest.fixtures.PathFixture('../../Utils/AugmentedMath') ...
        matlab.unittest.fixtures.PathFixture('../../Utils/CDMAnalysis') ...
        matlab.unittest.fixtures.PathFixture('../../Utils/CovarianceTransformations') ...
        matlab.unittest.fixtures.PathFixture('../../Utils/TimeTransformations') ...
        matlab.unittest.fixtures.PathFixture('../../Utils/LoggingAndStringReporting')}) ...
        Pc2D_Foster_UnitTest < matlab.unittest.TestCase
% Pc2D_Foster_UnitTest - Unit test for Pc2D_Foster
%
% =========================================================================
%
% Copyright (c) 2019-2025 United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================
% 
% Dependencies:
%
%   Pc_TestSetup.m
%
% =========================================================================
%
% Initial version: Dec 2019;  Latest update: Oct 2025
%
% ----------------- BEGIN CODE -----------------

    properties (TestParameter)
        AlfanoHBR = {15, 4, 15, 15, 10, 10, 10, 4, 6, 6, 4};
        AlfanoTLimit = {21600, 21600, 21600, 21600, 1419, 1419, 1419, 10135, 10800, 21600, 1420};
        AlfanoAccuracy = {0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001};                  
        AlfanoExpSolution = { 1.46749549E-01, ...
                              6.22226700E-03, ...
                              1.00351176E-01, ...
                              4.93234060E-02, ...
                              4.44873860E-02, ...
                              4.33545500E-03, ...
                              1.58147000E-04, ...
                              3.69480080E-02, ...
                              2.90146291E-01, ...
                              2.90146291E-01, ...
                              2.67202600E-03 };

        AlfanoFileNum = {'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11'};
        
        r1 = {[378.39559 4305.721887 5752.767554]};
        v1 = {[2.360800244 5.580331936 -4.322349039]};
        cov1 = {[ 44.5757544811362   81.6751751052616  -67.8687662707124;
                  81.6751751052616  158.453402956163  -128.616921644857;
                 -67.8687662707124 -128.616921644858   105.490542562701]};
        
        r2 = {[374.5180598 4307.560983 5751.130418]};
        v2 = {[-5.388125081 -3.946827739 3.322820358]};
        cov2 = {[ 2.31067077720423  1.69905293875632 -1.4170164577661;
                  1.69905293875632  1.24957388457206 -1.04174164279599;
                 -1.4170164577661  -1.04174164279599  0.869260558223714]};
             
        OmitronHBR = {0.020};
    end

    methods (Test)        
        function testCircularHBR(testCase, r1, v1, cov1, r2, v2, cov2, OmitronHBR) % Original Test Omitron Test Case 01 (Written by Dragan Plakalovic)
            % Circular Area
            expSolution = 2.70601573490125e-05;
            Accuracy = 0.001; 
            Tol = 1e-09;
            HBRType = 'circle';
            
            [actSolution] = Pc2D_Foster(r1,v1,cov1,r2,v2,cov2,OmitronHBR,Tol,HBRType);
            
            testCase.verifyEqual(actSolution,expSolution,'RelTol',Accuracy);
        end
        
        function testSquareHBR(testCase, r1, v1, cov1, r2, v2, cov2, OmitronHBR) % Original Test Omitron Test Case 02 (Written by Dragan Plakalovic)
            % Square Area
            expSolution = 3.44534649703584e-05;
            Accuracy = 0.001; 
            Tol = 1e-09;
            HBRType = 'square';
            
            [actSolution] = Pc2D_Foster(r1,v1,cov1,r2,v2,cov2,OmitronHBR,Tol,HBRType);
            
            testCase.verifyEqual(actSolution,expSolution,'RelTol',Accuracy);
        end
        
        function testEqAreaSquareHBR(testCase, r1, v1, cov1, r2, v2, cov2, OmitronHBR) % Original Test Omitron Test Case 03 (Written by Dragan Plakalovic)
            % Square Equivalent Area
            expSolution = 2.70601573490111e-05;
            Accuracy = 0.001; 
            Tol = 1e-09;
            HBRType = 'squareEquArea';
            
            [actSolution] = Pc2D_Foster(r1,v1,cov1,r2,v2,cov2,OmitronHBR,Tol,HBRType);
            
            testCase.verifyEqual(actSolution,expSolution,'RelTol',Accuracy);
        end
        
        function testNonPositiveDefinite(testCase) % Non-PD test Case
            HBR = 20;
            Accuracy = 1E-10; 
            expSolution = 0;

            [r1_J2K, v1_J2K, C1_J2K, r2_J2K, v2_J2K, C2_J2K] = Pc_TestSetup('../../../DataFiles/SampleCDMs/OmitronTestCase_Test07_NonPDCovariance.cdm');
                
            % Check for non- Positive Definite Error Throw
            [Pc2D,~,IsPosDef,IsRemediated]=Pc2D_Foster(r1_J2K*1000,v1_J2K*1000,C1_J2K,r2_J2K*1000,v2_J2K*1000,C2_J2K,HBR,1e-8,'circle');
            testCase.verifyEqual(Pc2D,expSolution,'AbsTol',Accuracy);
            testCase.verifyTrue(IsPosDef);
            testCase.verifyTrue(IsRemediated);
        end
        
        % Tests HBR type that is not 'circle', 'square', or 'squareEquArea'
        function testInvlidHBRType(testCase, r1, v1, cov1, r2, v2, cov2, OmitronHBR)
            Tol = 1e-09;
            HBRType = 'ellipse';
            
            testCase.verifyError(@() Pc2D_Foster(r1,v1,cov1,r2,v2,cov2,OmitronHBR,Tol,HBRType), 'Pc2D_Foster:InvalidHBRType');
        end
    end
    
    methods (Test, ParameterCombination = 'sequential')
        function testAlfano(testCase, AlfanoHBR, AlfanoAccuracy, AlfanoExpSolution, AlfanoFileNum)
            % Read tables of A09 at-TCA conjunction data
            pars.case_list = str2double(AlfanoFileNum);
            pars.data_path = '../../../DataFiles/AlfanoInputData/Alfano_2009_Test_Cases';
            conj = GetAlfanoTestCases(pars);
            r1_ECI = conj.X1(1:3)';

            v1_ECI = conj.X1(4:6)';
            C1_ECI = conj.C1;
            r2_ECI = conj.X2(1:3)';

            v2_ECI = conj.X2(4:6)';
            C2_ECI = conj.C2;
            
            actSolution = Pc2D_Foster(r1_ECI,v1_ECI,C1_ECI,r2_ECI,v2_ECI,C2_ECI,AlfanoHBR,1e-8,'circle');
                
            testCase.verifyEqual(actSolution,AlfanoExpSolution,'RelTol',AlfanoAccuracy);
        end
    end
end

% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history 
% shown below:
%
%---------------- CHANGE HISTORY ------------------
% Developer      |    Date    |     Description
%--------------------------------------------------
% T. Lechtenberg | 12-13-2019 | Initial Development
% L. Baars       | 10-03-2022 | Changed Alfano test case file reading
% E. White       | 08-07-2023 | Added compliant documentation, greatly
%                               improved readability and decreased length
%                               of unit tests
% E. White       | 08-09-2023 | Changed unit tests to use correct Alfano 
%                               data
% L. Baars       | 10-06-2025 | Updated path fixtures for more consistent
%                               passing runs.

% =========================================================================
%
% Copyright (c) 2019-2025 United States Government as represented by the
% Administrator of the National Aeronautics and Space Administration.
% All Rights Reserved.
%
% =========================================================================