summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cxg/cxg1001.a
blob: 01a0f061e516a551b8d4696e82983127e55c23a0 (plain)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
-- CXG1001.A
--
--                             Grant of Unlimited Rights
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained 
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making 
--     this public release, the Government intends to confer upon all 
--     recipients unlimited rights  equal to those held by the Government.  
--     These rights include rights to use, duplicate, release or disclose the 
--     released technical data and computer software in whole or in part, in 
--     any manner and for any purpose whatsoever, and to have or permit others 
--     to do so.
--
--                                    DISCLAIMER
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED 
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE 
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
--      Check that the subprograms defined in the package
--      Ada.Numerics.Generic_Complex_Types provide correct results.  
--      Specifically, check the functions Re, Im (both versions), procedures
--      Set_Re, Set_Im (both versions), functions Compose_From_Cartesian (all
--      versions), Compose_From_Polar, Modulus, Argument, and "abs".
--
-- TEST DESCRIPTION:
--      The generic package Generic_Complex_Types 
--      is instantiated with a real type (new Float), and the results
--      produced by the specified subprograms are verified.
--
-- APPLICABILITY CRITERIA:
--      This test applies only to implementations supporting the
--      Numerics Annex.
--
--       
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      15 Nov 95   SAIC    Corrected visibility problems for ACVC 2.0.1.
--                          Modified subtest for Compose_From_Polar.
--      29 Sep 96   SAIC    Incorporated reviewer comments.
--
--!

with Ada.Numerics.Generic_Complex_Types;
with Report;

procedure CXG1001 is

begin

   Report.Test ("CXG1001", "Check that the subprograms defined in " &
                           "the package Ada.Numerics.Generic_Complex_Types " & 
                           "provide correct results");

   Test_Block:
   declare

      type Real_Type is new Float;

      package Complex_Pack is new 
        Ada.Numerics.Generic_Complex_Types(Real_Type);

      use type Complex_Pack.Complex;

      -- Declare a zero valued complex number.
      Complex_Zero : constant Complex_Pack.Complex := (0.0, 0.0);

      TC_Complex   : Complex_Pack.Complex := Complex_Zero;
      TC_Imaginary : Complex_Pack.Imaginary;    

   begin

      -- Check that the procedures Set_Re and Set_Im (both versions) provide
      -- correct results.

      declare
         TC_Complex_Real_Field : Complex_Pack.Complex := (5.0, 0.0);
         TC_Complex_Both_Fields : Complex_Pack.Complex := (5.0, 7.0);
      begin

         Complex_Pack.Set_Re(X => TC_Complex, Re => 5.0);

         if TC_Complex /= TC_Complex_Real_Field then
            Report.Failed("Incorrect results from Procedure Set_Re");
         end if;

         Complex_Pack.Set_Im(X => TC_Complex, Im => 7.0);

         if TC_Complex.Re /= 5.0 or
            TC_Complex.Im /= 7.0 or
            TC_Complex    /= TC_Complex_Both_Fields 
         then
            Report.Failed("Incorrect results from Procedure Set_Im " &
                          "with Complex argument");
         end if;

         Complex_Pack.Set_Im(X => TC_Imaginary, Im => 3.0);


         if Complex_Pack.Im(TC_Imaginary) /= 3.0 then
            Report.Failed("Incorrect results returned following the use " &
                          "of Procedure Set_Im with Imaginary argument");
         end if;

      end;


      -- Check that the functions Re and Im (both versions) provide
      -- correct results.

      declare
         TC_Complex_1 : Complex_Pack.Complex := (1.0, 0.0);
         TC_Complex_2 : Complex_Pack.Complex := (0.0, 2.0);
         TC_Complex_3 : Complex_Pack.Complex := (4.0, 3.0);
      begin

         -- Function Re.

         if Complex_Pack.Re(X => TC_Complex_1) /= 1.0  or
            Complex_Pack.Re(X => TC_Complex_2) /= 0.0  or
            Complex_Pack.Re(X => TC_Complex_3) /= 4.0 
         then
            Report.Failed("Incorrect results from Function Re");
         end if;

         -- Function Im; version with Complex argument.

         if Complex_Pack.Im(X => TC_Complex_1) /= 0.0  or
            Complex_Pack.Im(X => TC_Complex_2) /= 2.0  or
            Complex_Pack.Im(X => TC_Complex_3) /= 3.0 
         then
            Report.Failed("Incorrect results from Function Im " &
                          "with Complex argument");
         end if;


         -- Function Im; version with Imaginary argument.

         if Complex_Pack.Im(Complex_Pack.i) /= 1.0  or
            Complex_Pack.Im(Complex_Pack.j) /= 1.0
         then
            Report.Failed("Incorrect results from use of Function Im " &
                          "when used with an Imaginary argument");
         end if;

      end;


      -- Verify the results of the three versions of Function
      -- Compose_From_Cartesian

      declare

         Zero  : constant Real_Type := 0.0;
         Six   : constant Real_Type := 6.0;

         TC_Complex_1 : Complex_Pack.Complex := (3.0, 8.0);
         TC_Complex_2 : Complex_Pack.Complex := (Six, Zero);
         TC_Complex_3 : Complex_Pack.Complex := (Zero, 1.0);

      begin

         TC_Complex := Complex_Pack.Compose_From_Cartesian(3.0, 8.0);

         if TC_Complex /= TC_Complex_1 then
            Report.Failed("Incorrect results from Function " &
                          "Compose_From_Cartesian - 1");
         end if;

         -- If only one component is given, the other component is 
         -- implicitly zero (Both components are set by the following two
         -- function calls).

         TC_Complex := Complex_Pack.Compose_From_Cartesian(Re => 6.0);

         if TC_Complex /= TC_Complex_2 then
            Report.Failed("Incorrect results from Function " &
                          "Compose_From_Cartesian - 2");
         end if;

         TC_Complex := 
           Complex_Pack.Compose_From_Cartesian(Im => Complex_Pack.i);

         if TC_Complex /= TC_Complex_3 then
            Report.Failed("Incorrect results from Function " &
                          "Compose_From_Cartesian - 3");
         end if;

      end; 


      -- Verify the results of Function Compose_From_Polar, Modulus, "abs",
      -- and Argument.

      declare

         use Complex_Pack;

         TC_Modulus,
         TC_Argument : Real_Type := 0.0;


         Angle_0     : constant Real_Type :=   0.0;
         Angle_90    : constant Real_Type :=  90.0;
         Angle_180   : constant Real_Type := 180.0;
         Angle_270   : constant Real_Type := 270.0;
         Angle_360   : constant Real_Type := 360.0;

      begin

         -- Verify the result of Function Compose_From_Polar.
         -- When the value of the parameter Modulus is zero, the 
         -- Compose_From_Polar function yields a result of zero.

         if Compose_From_Polar(0.0, 30.0, 360.0) /= Complex_Zero
         then
            Report.Failed("Incorrect result from Function " &
                          "Compose_From_Polar - 1");
         end if;

         -- When the value of the parameter Argument is equal to a multiple
         -- of the quarter cycle, the result of the Compose_From_Polar
         -- function with specified cycle lies on one of the axes.

         if Compose_From_Polar( 5.0,  Angle_0,   Angle_360) /= (5.0,  0.0) or
            Compose_From_Polar( 5.0,  Angle_90,  Angle_360) /= (0.0,  5.0) or
            Compose_From_Polar(-5.0,  Angle_180, Angle_360) /= (5.0,  0.0) or
            Compose_From_Polar(-5.0,  Angle_270, Angle_360) /= (0.0,  5.0) or
            Compose_From_Polar(-5.0,  Angle_90,  Angle_360) /= (0.0, -5.0) or
            Compose_From_Polar( 5.0,  Angle_270, Angle_360) /= (0.0, -5.0) 
         then
            Report.Failed("Incorrect result from Function " &
                          "Compose_From_Polar - 2");
         end if;

         -- When the parameter to Function Argument represents a point on 
         -- the non-negative real axis, the function yields a zero result.

         if Argument(Complex_Zero, Angle_360) /= 0.0 then
            Report.Failed("Incorrect result from Function Argument");
         end if;

         -- Function Modulus

         if Modulus(Complex_Zero) /= 0.0  or
            Modulus(Compose_From_Polar( 5.0, Angle_90,  Angle_360)) /= 5.0 or
            Modulus(Compose_From_Polar(-5.0, Angle_180, Angle_360)) /= 5.0 
         then
            Report.Failed("Incorrect results from Function Modulus");
         end if;

         -- Function "abs", a rename of Function Modulus.

         if "abs"(Complex_Zero) /= 0.0  or
            "abs"(Compose_From_Polar( 5.0, Angle_90,  Angle_360)) /= 5.0 or
            "abs"(Compose_From_Polar(-5.0, Angle_180, Angle_360)) /= 5.0 
         then
            Report.Failed("Incorrect results from Function abs");
         end if;

      end;

   exception
      when others => Report.Failed ("Exception raised in Test_Block");
   end Test_Block;

   Report.Result;

end CXG1001;