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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
|
-- C450001.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 operations on modular types perform correctly.
--
-- Check that loops over the range of a modular type do not over or
-- under run the loop.
--
-- TEST DESCRIPTION:
-- Check logical and arithmetic operations.
-- (Attributes are tested elsewhere)
-- Checks to make sure that:
-- for X in Mod_Type loop
-- doesn't do something silly like infinite loop.
--
--
-- CHANGE HISTORY:
-- 20 SEP 95 SAIC Initial version
-- 20 FEB 96 SAIC Added underrun cases for 2.1
--
--!
----------------------------------------------------------------- C450001_0
package C450001_0 is
type Unsigned_8_Bit is mod 2**8;
Shy_By_One : constant := 2**8-1;
Heavy_By_Two : constant := 2**8+2;
type Unsigned_Edge_8 is mod Shy_By_One;
type Unsigned_Over_8 is mod Heavy_By_Two;
procedure Loop_Check;
-- embed some calls to Report.Ident_Int:
function ID( U8B: Unsigned_8_Bit ) return Unsigned_8_Bit;
function ID( UEB: Unsigned_Edge_8 ) return Unsigned_Edge_8;
function ID( UOB: Unsigned_Over_8 ) return Unsigned_Over_8;
end C450001_0;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
with Report;
package body C450001_0 is
procedure Loop_Check is
Counter_Check : Natural := 0;
begin
for Ever in Unsigned_8_Bit loop
Counter_Check := Report.Ident_Int(Counter_Check) + 1;
if Counter_Check > 2**8 then
Report.Failed("Unsigned_8_Bit loop overrun");
exit;
end if;
end loop;
if Counter_Check < 2**8 then
Report.Failed("Unsigned_8_Bit loop underrun");
end if;
Counter_Check := 0;
for Never in Unsigned_Edge_8 loop
Counter_Check := Report.Ident_Int(Counter_Check) + 1;
if Counter_Check > Shy_By_One then
Report.Failed("Unsigned_Edge_8 loop overrun");
exit;
end if;
end loop;
if Counter_Check < Shy_By_One then
Report.Failed("Unsigned_Edge_8 loop underrun");
end if;
Counter_Check := 0;
for Getful in reverse Unsigned_Over_8 loop
Counter_Check := Report.Ident_Int(Counter_Check) + 1;
if Counter_Check > Heavy_By_Two then
Report.Failed("Unsigned_Over_8 loop overrun");
exit;
end if;
end loop;
if Counter_Check < Heavy_By_Two then
Report.Failed("Unsigned_Over_8 loop underrun");
end if;
end Loop_Check;
function ID( U8B: Unsigned_8_Bit ) return Unsigned_8_Bit is
begin
return Unsigned_8_Bit(Report.Ident_Int(Integer(U8B)));
end ID;
function ID( UEB: Unsigned_Edge_8 ) return Unsigned_Edge_8 is
begin
return Unsigned_Edge_8(Report.Ident_Int(Integer(UEB)));
end ID;
function ID( UOB: Unsigned_Over_8 ) return Unsigned_Over_8 is
begin
return Unsigned_Over_8(Report.Ident_Int(Integer(UOB)));
end ID;
end C450001_0;
------------------------------------------------------------------- C450001
with Report;
with C450001_0;
with TCTouch;
procedure C450001 is
use C450001_0;
BR : constant String := " produced the wrong result";
procedure Is_T(B:Boolean;S:String) renames TCTouch.Assert;
procedure Is_F(B:Boolean;S:String) renames TCTouch.Assert_Not;
Whole_8_A, Whole_8_B, Whole_8_C : C450001_0.Unsigned_8_Bit;
Short_8_A, Short_8_B, Short_8_C : C450001_0.Unsigned_Edge_8;
Over_8_A, Over_8_B, Over_8_C : C450001_0.Unsigned_Over_8;
begin -- Main test procedure. C450001
Report.Test ("C450001", "Check that operations on modular types " &
"perform correctly." );
-- the cases for the whole 8 bit type are pretty simple
Whole_8_A := 2#00000000#;
Whole_8_B := 2#11111111#;
Is_T((ID(Whole_8_A) and ID(Whole_8_B)) = 2#00000000#,"8 bit and" & BR);
Is_T((ID(Whole_8_A) or ID(Whole_8_B)) = 2#11111111#,"8 bit or" & BR);
Is_T((ID(Whole_8_A) xor ID(Whole_8_B)) = 2#11111111#,"8 bit xor" & BR);
Whole_8_A := 2#00001111#;
Whole_8_B := 2#11111111#;
Is_T((ID(Whole_8_A) and ID(Whole_8_B)) = 2#00001111#,"8 bit and" & BR);
Is_T((ID(Whole_8_A) or ID(Whole_8_B)) = 2#11111111#,"8 bit or" & BR);
Is_T((ID(Whole_8_A) xor ID(Whole_8_B)) = 2#11110000#,"8 bit xor" & BR);
Whole_8_A := 2#10101010#;
Whole_8_B := 2#11110000#;
Is_T((ID(Whole_8_A) and ID(Whole_8_B)) = 2#10100000#,"8 bit and" & BR);
Is_T((ID(Whole_8_A) or ID(Whole_8_B)) = 2#11111010#,"8 bit or" & BR);
Is_T((ID(Whole_8_A) xor ID(Whole_8_B)) = 2#01011010#,"8 bit xor" & BR);
-- the cases for the partial 8 bit type involve subtracting the modulus
-- from results that exceed the modulus.
-- hence, any of the following operations that exceed 2#11111110# must
-- have 2#11111111# subtracted from the result; i.e. where you would
-- expect to see 2#11111111# as in the above operations, the correct
-- result will be 2#00000000#. Note that 2#11111111# is not a legal
-- value of type C450001_0.Unsigned_Edge_8.
Short_8_A := 2#11100101#;
Short_8_B := 2#00011111#;
Is_T((ID(Short_8_A) and ID(Short_8_B)) = 2#00000101#,"8 short and 1" & BR);
Is_T((ID(Short_8_A) or ID(Short_8_B)) = 2#00000000#,"8 short or 1" & BR);
Is_T((ID(Short_8_A) xor ID(Short_8_B)) = 2#11111010#,"8 short xor 1" & BR);
Short_8_A := 2#11110000#;
Short_8_B := 2#11111110#;
Is_T((ID(Short_8_A) and ID(Short_8_B)) = 2#11110000#,"8 short and 2" & BR);
Is_T((ID(Short_8_A) or ID(Short_8_B)) = 2#11111110#,"8 short or 2" & BR);
Is_T((ID(Short_8_A) xor ID(Short_8_B)) = 2#00001110#,"8 short xor 2" & BR);
Short_8_A := 2#10101010#;
Short_8_B := 2#01010101#;
Is_T((ID(Short_8_A) and ID(Short_8_B)) = 2#00000000#,"8 short and 3" & BR);
Is_T((ID(Short_8_A) or ID(Short_8_B)) = 2#00000000#,"8 short or 3" & BR);
Is_T((ID(Short_8_A) xor ID(Short_8_B)) = 2#00000000#,"8 short xor 3" & BR);
Short_8_A := 2#10101010#;
Short_8_B := 2#11111110#;
Is_T((ID(Short_8_A) and ID(Short_8_B)) = 2#10101010#,"8 short and 4" & BR);
Is_T((ID(Short_8_A) or ID(Short_8_B)) = 2#11111110#,"8 short or 4" & BR);
Is_T((ID(Short_8_A) xor ID(Short_8_B)) = 2#01010100#,"8 short xor 4" & BR);
-- the cases for the over 8 bit type have similar issues to the short type
-- however the bit patterns are a little different. The rule is to subtract
-- the modulus (258) from any resulting value equal or greater than the
-- modulus -- note that 258 = 2#100000010#
Over_8_A := 2#100000000#;
Over_8_B := 2#011111111#;
Is_T((ID(Over_8_A) and ID(Over_8_B)) = 2#000000000#,"8 over and" & BR);
Is_T((ID(Over_8_A) or ID(Over_8_B)) = 2#011111101#,"8 over or" & BR);
Is_T((ID(Over_8_A) xor ID(Over_8_B)) = 2#011111101#,"8 over xor" & BR);
Over_8_A := 2#100000001#;
Over_8_B := 2#011111111#;
Is_T((ID(Over_8_A) and ID(Over_8_B)) = 2#000000001#,"8 over and" & BR);
Is_T((ID(Over_8_A) or ID(Over_8_B)) = 2#011111101#,"8 over or" & BR);
Is_T((ID(Over_8_A) xor ID(Over_8_B)) = 2#011111100#,"8 over xor" & BR);
Whole_8_A := 128;
Whole_8_B := 255;
Is_T(ID(Whole_8_A) /= ID(Whole_8_B), "8 /=" & BR);
Is_F(ID(Whole_8_A) = ID(Whole_8_B), "8 =" & BR);
Is_T(ID(Whole_8_A) <= ID(Whole_8_B), "8 <=" & BR);
Is_T(ID(Whole_8_A) < ID(Whole_8_B), "8 < " & BR);
Is_F(ID(Whole_8_A) >= ID(Whole_8_B), "8 >=" & BR);
Is_T(ID(Whole_8_A) > ID(Whole_8_B + 7), "8 > " & BR);
Is_T(ID(Whole_8_A) in ID(100)..ID(200), "8 in" & BR);
Is_F(ID(Whole_8_A) not in ID(100)..ID(200), "8 not in" & BR);
Is_F(ID(Whole_8_A) in ID(200)..ID(250), "8 in" & BR);
Is_T(ID(Whole_8_A) not in ID(200)..ID(250), "8 not in" & BR);
Short_8_A := 127;
Short_8_B := 254;
Is_T(ID(Short_8_A) /= ID(Short_8_B), "short 8 /=" & BR);
Is_F(ID(Short_8_A) = ID(Short_8_B), "short 8 =" & BR);
Is_T(ID(Short_8_A) <= ID(Short_8_B), "short 8 <=" & BR);
Is_T(ID(Short_8_A) < ID(Short_8_B), "short 8 < " & BR);
Is_F(ID(Short_8_A) >= ID(Short_8_B), "short 8 >=" & BR);
Is_F(ID(Short_8_A) > ID(Short_8_B), "short 8 > " & BR);
Is_T(ID(Short_8_A) in ID(100)..ID(200), "8 in" & BR);
Is_F(ID(Short_8_A) not in ID(100)..ID(200), "8 not in" & BR);
Is_F(ID(Short_8_A) in ID(200)..ID(250), "8 in" & BR);
Is_T(ID(Short_8_A) not in ID(200)..ID(250), "8 not in" & BR);
Whole_8_A := 1;
Whole_8_B := 254;
Short_8_A := 1;
Short_8_B := 2;
Whole_8_C := ID(Whole_8_A) + ID(Whole_8_B);
Is_T(Whole_8_C = C450001_0.Unsigned_8_Bit'Last, "8 binary + 1" & BR);
Whole_8_C := Whole_8_C + ID(Whole_8_A);
Is_T(Whole_8_C = C450001_0.Unsigned_8_Bit'First, "8 binary + 2" & BR);
Whole_8_C := ID(Whole_8_A) - ID(Whole_8_A);
Is_T(Whole_8_C = 0, "8 binary -" & BR);
Whole_8_C := Whole_8_C - ID(Whole_8_A);
Is_T(Whole_8_C = C450001_0.Unsigned_8_Bit'Last, "8 binary + 3" & BR);
Short_8_C := ID(Short_8_A) + ID(C450001_0.Unsigned_Edge_8'Last);
Is_T(Short_8_C = C450001_0.Unsigned_Edge_8'First, "Short binary + 1" & BR);
Short_8_C := Short_8_A + ID(Short_8_A);
Is_T(Short_8_C = ID(Short_8_B), "Short binary + 2" & BR);
Short_8_C := ID(Short_8_A) - ID(Short_8_A);
Is_T(Short_8_C = 0, "Short 8 binary -" & BR);
Short_8_C := Short_8_C - ID(Short_8_A);
Is_T(Short_8_C = C450001_0.Unsigned_Edge_8'Last, "Short binary + 3" & BR);
Whole_8_C := ( + ID(Whole_8_B) );
Is_T(Whole_8_C = 254, "8 unary +" & BR);
Whole_8_C := ( - ID(Whole_8_A) );
Is_T(Whole_8_C = C450001_0.Unsigned_8_Bit'Last, "8 unary -" & BR);
Whole_8_C := ( - ID(0) );
Is_T(Whole_8_C = 0, "8 unary -0" & BR);
Short_8_C := ( + ID(C450001_0.Unsigned_Edge_8'Last) );
Is_T(Short_8_C = 254, "Short 8 unary +" & BR);
Short_8_C := ( - ID(Short_8_A) );
Is_T(Short_8_C = C450001_0.Unsigned_Edge_8'Last, "Short 8 unary -" & BR);
Whole_8_A := 20;
Whole_8_B := 255;
Whole_8_C := ID(Whole_8_A) * ID(Whole_8_B); -- 5100 = 19*256 + 236 (256-20)
Is_T(Whole_8_C = 236, "8 *" & BR);
Short_8_A := 9;
Short_8_B := 254;
Short_8_C := ID(Short_8_A) * ID(Short_8_B); -- 2286 = 8*255 + 246 (255-9)
Is_T(Short_8_C = 246, "short 8 *" & BR);
Over_8_A := 12;
Over_8_B := 86;
Over_8_C := ID(Over_8_A) * ID(Over_8_B); -- 1032 = 4*258 + 0
Is_T(Over_8_C = 0, "over 8 *" & BR);
Whole_8_A := 255;
Whole_8_B := 4;
Whole_8_C := ID(Whole_8_A) / ID(Whole_8_B);
Is_T(Whole_8_C = 63, "8 /" & BR);
Short_8_A := 253;
Short_8_B := 127;
Short_8_C := ID(Short_8_A) / ID(Short_8_B);
Is_T(Short_8_C = 1, "short 8 / 1" & BR);
Short_8_C := ID(Short_8_A) / ID(126);
Is_T(Short_8_C = 2, "short 8 / 2" & BR);
Whole_8_A := 255;
Whole_8_B := 254;
Whole_8_C := ID(Whole_8_A) rem ID(Whole_8_B);
Is_T(Whole_8_C = 1, "8 rem" & BR);
Short_8_A := 222;
Short_8_B := 111;
Short_8_C := ID(Short_8_A) rem ID(Short_8_B);
Is_T(Short_8_C = 0, "short 8 rem" & BR);
Whole_8_A := 99;
Whole_8_B := 9;
Whole_8_C := ID(Whole_8_A) mod ID(Whole_8_B);
Is_T(Whole_8_C = 0, "8 mod" & BR);
Short_8_A := 254;
Short_8_B := 250;
Short_8_C := ID(Short_8_A) mod ID(Short_8_B);
Is_T(Short_8_C = 4, "short 8 mod" & BR);
Whole_8_A := 99;
Whole_8_C := abs Whole_8_A;
Is_T(Whole_8_C = ID(99), "8 abs" & BR);
Short_8_A := 254;
Short_8_C := ID( abs Short_8_A );
Is_T(Short_8_C = 254, "short 8 abs" & BR);
Whole_8_B := 2#00001111#;
Whole_8_C := not Whole_8_B;
Is_T(Whole_8_C = ID(2#11110000#), "8 not" & BR);
Short_8_B := 2#00001111#; -- 15
Short_8_C := ID( not Short_8_B ); -- 254 - 15
Is_T(Short_8_C = 2#11101111#, "short 8 not" & BR); -- 239
Whole_8_A := 2;
Whole_8_C := Whole_8_A ** 7;
Is_T(Whole_8_C = ID(128), "2 ** 7, whole 8" & BR);
Whole_8_C := Whole_8_A ** 9;
Is_T(Whole_8_C = ID(0), "2 ** 9, whole 8" & BR);
Short_8_A := 4;
Short_8_C := ID( Short_8_A ) ** 4;
Is_T(Short_8_C = 1, "4 ** 4, short" & BR);
Over_8_A := 4;
Over_8_C := ID( Over_8_A ) ** 4;
Is_T(Over_8_C = 256, "4 ** 4, over" & BR);
Over_8_C := ID( Over_8_A ) ** 5; -- 1024 = 3*258 + 250
Is_T(Over_8_C = 250, "4 ** 5, over" & BR);
C450001_0.Loop_Check;
Report.Result;
end C450001;
|