2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / ada / acats / tests / cxg / cxg1001.a
blob01a0f061e516a551b8d4696e82983127e55c23a0
1 -- CXG1001.A
2 --
3 -- Grant of Unlimited Rights
4 --
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
14 -- to do so.
16 -- DISCLAIMER
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.
24 --*
26 -- OBJECTIVE:
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".
33 -- TEST DESCRIPTION:
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
40 -- Numerics Annex.
42 --
43 -- CHANGE HISTORY:
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.
49 --!
51 with Ada.Numerics.Generic_Complex_Types;
52 with Report;
54 procedure CXG1001 is
56 begin
58 Report.Test ("CXG1001", "Check that the subprograms defined in " &
59 "the package Ada.Numerics.Generic_Complex_Types " &
60 "provide correct results");
62 Test_Block:
63 declare
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;
78 begin
80 -- Check that the procedures Set_Re and Set_Im (both versions) provide
81 -- correct results.
83 declare
84 TC_Complex_Real_Field : Complex_Pack.Complex := (5.0, 0.0);
85 TC_Complex_Both_Fields : Complex_Pack.Complex := (5.0, 7.0);
86 begin
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");
92 end if;
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
99 then
100 Report.Failed("Incorrect results from Procedure Set_Im " &
101 "with Complex argument");
102 end if;
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");
110 end if;
112 end;
115 -- Check that the functions Re and Im (both versions) provide
116 -- correct results.
118 declare
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);
122 begin
124 -- Function Re.
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
129 then
130 Report.Failed("Incorrect results from Function Re");
131 end if;
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
138 then
139 Report.Failed("Incorrect results from Function Im " &
140 "with Complex argument");
141 end if;
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
148 then
149 Report.Failed("Incorrect results from use of Function Im " &
150 "when used with an Imaginary argument");
151 end if;
153 end;
156 -- Verify the results of the three versions of Function
157 -- Compose_From_Cartesian
159 declare
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);
168 begin
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");
175 end if;
177 -- If only one component is given, the other component is
178 -- implicitly zero (Both components are set by the following two
179 -- function calls).
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");
186 end if;
188 TC_Complex :=
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");
194 end if;
196 end;
199 -- Verify the results of Function Compose_From_Polar, Modulus, "abs",
200 -- and Argument.
202 declare
204 use Complex_Pack;
206 TC_Modulus,
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;
216 begin
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
223 then
224 Report.Failed("Incorrect result from Function " &
225 "Compose_From_Polar - 1");
226 end if;
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)
238 then
239 Report.Failed("Incorrect result from Function " &
240 "Compose_From_Polar - 2");
241 end if;
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");
248 end if;
250 -- Function Modulus
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
255 then
256 Report.Failed("Incorrect results from Function Modulus");
257 end if;
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
264 then
265 Report.Failed("Incorrect results from Function abs");
266 end if;
268 end;
270 exception
271 when others => Report.Failed ("Exception raised in Test_Block");
272 end Test_Block;
274 Report.Result;
276 end CXG1001;