3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that the subprograms defined in the package
28 -- Ada.Numerics.Generic_Complex_Types provide correct results.
29 -- Specifically, check the functions Re, Im (both versions), procedures
30 -- Set_Re, Set_Im (both versions), functions Compose_From_Cartesian (all
31 -- versions), Compose_From_Polar, Modulus, Argument, and "abs".
34 -- The generic package Generic_Complex_Types
35 -- is instantiated with a real type (new Float), and the results
36 -- produced by the specified subprograms are verified.
38 -- APPLICABILITY CRITERIA:
39 -- This test applies only to implementations supporting the
44 -- 06 Dec 94 SAIC ACVC 2.0
45 -- 15 Nov 95 SAIC Corrected visibility problems for ACVC 2.0.1.
46 -- Modified subtest for Compose_From_Polar.
47 -- 29 Sep 96 SAIC Incorporated reviewer comments.
51 with Ada
.Numerics
.Generic_Complex_Types
;
58 Report
.Test
("CXG1001", "Check that the subprograms defined in " &
59 "the package Ada.Numerics.Generic_Complex_Types " &
60 "provide correct results");
65 type Real_Type
is new Float;
67 package Complex_Pack
is new
68 Ada
.Numerics
.Generic_Complex_Types
(Real_Type
);
70 use type Complex_Pack
.Complex
;
72 -- Declare a zero valued complex number.
73 Complex_Zero
: constant Complex_Pack
.Complex
:= (0.0, 0.0);
75 TC_Complex
: Complex_Pack
.Complex
:= Complex_Zero
;
76 TC_Imaginary
: Complex_Pack
.Imaginary
;
80 -- Check that the procedures Set_Re and Set_Im (both versions) provide
84 TC_Complex_Real_Field
: Complex_Pack
.Complex
:= (5.0, 0.0);
85 TC_Complex_Both_Fields
: Complex_Pack
.Complex
:= (5.0, 7.0);
88 Complex_Pack
.Set_Re
(X
=> TC_Complex
, Re
=> 5.0);
90 if TC_Complex
/= TC_Complex_Real_Field
then
91 Report
.Failed
("Incorrect results from Procedure Set_Re");
94 Complex_Pack
.Set_Im
(X
=> TC_Complex
, Im
=> 7.0);
96 if TC_Complex
.Re
/= 5.0 or
97 TC_Complex
.Im
/= 7.0 or
98 TC_Complex
/= TC_Complex_Both_Fields
100 Report
.Failed
("Incorrect results from Procedure Set_Im " &
101 "with Complex argument");
104 Complex_Pack
.Set_Im
(X
=> TC_Imaginary
, Im
=> 3.0);
107 if Complex_Pack
.Im
(TC_Imaginary
) /= 3.0 then
108 Report
.Failed
("Incorrect results returned following the use " &
109 "of Procedure Set_Im with Imaginary argument");
115 -- Check that the functions Re and Im (both versions) provide
119 TC_Complex_1
: Complex_Pack
.Complex
:= (1.0, 0.0);
120 TC_Complex_2
: Complex_Pack
.Complex
:= (0.0, 2.0);
121 TC_Complex_3
: Complex_Pack
.Complex
:= (4.0, 3.0);
126 if Complex_Pack
.Re
(X
=> TC_Complex_1
) /= 1.0 or
127 Complex_Pack
.Re
(X
=> TC_Complex_2
) /= 0.0 or
128 Complex_Pack
.Re
(X
=> TC_Complex_3
) /= 4.0
130 Report
.Failed
("Incorrect results from Function Re");
133 -- Function Im; version with Complex argument.
135 if Complex_Pack
.Im
(X
=> TC_Complex_1
) /= 0.0 or
136 Complex_Pack
.Im
(X
=> TC_Complex_2
) /= 2.0 or
137 Complex_Pack
.Im
(X
=> TC_Complex_3
) /= 3.0
139 Report
.Failed
("Incorrect results from Function Im " &
140 "with Complex argument");
144 -- Function Im; version with Imaginary argument.
146 if Complex_Pack
.Im
(Complex_Pack
.i
) /= 1.0 or
147 Complex_Pack
.Im
(Complex_Pack
.j
) /= 1.0
149 Report
.Failed
("Incorrect results from use of Function Im " &
150 "when used with an Imaginary argument");
156 -- Verify the results of the three versions of Function
157 -- Compose_From_Cartesian
161 Zero
: constant Real_Type
:= 0.0;
162 Six
: constant Real_Type
:= 6.0;
164 TC_Complex_1
: Complex_Pack
.Complex
:= (3.0, 8.0);
165 TC_Complex_2
: Complex_Pack
.Complex
:= (Six
, Zero
);
166 TC_Complex_3
: Complex_Pack
.Complex
:= (Zero
, 1.0);
170 TC_Complex
:= Complex_Pack
.Compose_From_Cartesian
(3.0, 8.0);
172 if TC_Complex
/= TC_Complex_1
then
173 Report
.Failed
("Incorrect results from Function " &
174 "Compose_From_Cartesian - 1");
177 -- If only one component is given, the other component is
178 -- implicitly zero (Both components are set by the following two
181 TC_Complex
:= Complex_Pack
.Compose_From_Cartesian
(Re
=> 6.0);
183 if TC_Complex
/= TC_Complex_2
then
184 Report
.Failed
("Incorrect results from Function " &
185 "Compose_From_Cartesian - 2");
189 Complex_Pack
.Compose_From_Cartesian
(Im
=> Complex_Pack
.i
);
191 if TC_Complex
/= TC_Complex_3
then
192 Report
.Failed
("Incorrect results from Function " &
193 "Compose_From_Cartesian - 3");
199 -- Verify the results of Function Compose_From_Polar, Modulus, "abs",
207 TC_Argument
: Real_Type
:= 0.0;
210 Angle_0
: constant Real_Type
:= 0.0;
211 Angle_90
: constant Real_Type
:= 90.0;
212 Angle_180
: constant Real_Type
:= 180.0;
213 Angle_270
: constant Real_Type
:= 270.0;
214 Angle_360
: constant Real_Type
:= 360.0;
218 -- Verify the result of Function Compose_From_Polar.
219 -- When the value of the parameter Modulus is zero, the
220 -- Compose_From_Polar function yields a result of zero.
222 if Compose_From_Polar
(0.0, 30.0, 360.0) /= Complex_Zero
224 Report
.Failed
("Incorrect result from Function " &
225 "Compose_From_Polar - 1");
228 -- When the value of the parameter Argument is equal to a multiple
229 -- of the quarter cycle, the result of the Compose_From_Polar
230 -- function with specified cycle lies on one of the axes.
232 if Compose_From_Polar
( 5.0, Angle_0
, Angle_360
) /= (5.0, 0.0) or
233 Compose_From_Polar
( 5.0, Angle_90
, Angle_360
) /= (0.0, 5.0) or
234 Compose_From_Polar
(-5.0, Angle_180
, Angle_360
) /= (5.0, 0.0) or
235 Compose_From_Polar
(-5.0, Angle_270
, Angle_360
) /= (0.0, 5.0) or
236 Compose_From_Polar
(-5.0, Angle_90
, Angle_360
) /= (0.0, -5.0) or
237 Compose_From_Polar
( 5.0, Angle_270
, Angle_360
) /= (0.0, -5.0)
239 Report
.Failed
("Incorrect result from Function " &
240 "Compose_From_Polar - 2");
243 -- When the parameter to Function Argument represents a point on
244 -- the non-negative real axis, the function yields a zero result.
246 if Argument
(Complex_Zero
, Angle_360
) /= 0.0 then
247 Report
.Failed
("Incorrect result from Function Argument");
252 if Modulus
(Complex_Zero
) /= 0.0 or
253 Modulus
(Compose_From_Polar
( 5.0, Angle_90
, Angle_360
)) /= 5.0 or
254 Modulus
(Compose_From_Polar
(-5.0, Angle_180
, Angle_360
)) /= 5.0
256 Report
.Failed
("Incorrect results from Function Modulus");
259 -- Function "abs", a rename of Function Modulus.
261 if "abs"(Complex_Zero
) /= 0.0 or
262 "abs"(Compose_From_Polar
( 5.0, Angle_90
, Angle_360
)) /= 5.0 or
263 "abs"(Compose_From_Polar
(-5.0, Angle_180
, Angle_360
)) /= 5.0
265 Report
.Failed
("Incorrect results from Function abs");
271 when others => Report
.Failed
("Exception raised in Test_Block");