-- CXA5011.A
|
-- CXA5011.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- 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
|
-- 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 in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- 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
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that, for both Float_Random and Discrete_Random packages,
|
-- Check that, for both Float_Random and Discrete_Random packages,
|
-- the following are true:
|
-- the following are true:
|
-- 1) two objects of type Generator are initialized to the same state.
|
-- 1) two objects of type Generator are initialized to the same state.
|
-- 2) when the Function Reset is used to reset two generators
|
-- 2) when the Function Reset is used to reset two generators
|
-- to different time-dependent states, the resulting random values
|
-- to different time-dependent states, the resulting random values
|
-- from each generator are different.
|
-- from each generator are different.
|
-- 3) when the Function Reset uses the same integer initiator
|
-- 3) when the Function Reset uses the same integer initiator
|
-- to reset two generators to the same state, the resulting random
|
-- to reset two generators to the same state, the resulting random
|
-- values from each generator are identical.
|
-- values from each generator are identical.
|
-- 4) when the Function Reset uses different integer initiator
|
-- 4) when the Function Reset uses different integer initiator
|
-- values to reset two generators, the resulting random numbers are
|
-- values to reset two generators, the resulting random numbers are
|
-- different.
|
-- different.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test evaluates components of the Ada.Numerics.Float_Random and
|
-- This test evaluates components of the Ada.Numerics.Float_Random and
|
-- Ada.Numerics.Discrete_Random packages.
|
-- Ada.Numerics.Discrete_Random packages.
|
-- This test checks to see that objects of type Generator are initialized
|
-- This test checks to see that objects of type Generator are initialized
|
-- to the same state. In addition, the functionality of Function Reset is
|
-- to the same state. In addition, the functionality of Function Reset is
|
-- validated.
|
-- validated.
|
-- For each of the objectives above, evaluation of the various generators
|
-- For each of the objectives above, evaluation of the various generators
|
-- is performed using each of the following techniques. When the states of
|
-- is performed using each of the following techniques. When the states of
|
-- two generators are to be compared, each state is saved, then
|
-- two generators are to be compared, each state is saved, then
|
-- transformed to a bounded-string variable. The bounded-strings can
|
-- transformed to a bounded-string variable. The bounded-strings can
|
-- then be compared for equality. In this case, matching bounded-strings
|
-- then be compared for equality. In this case, matching bounded-strings
|
-- are evidence that the states of two generators are the same.
|
-- are evidence that the states of two generators are the same.
|
-- In addition, two generators are compared by evaluating a series of
|
-- In addition, two generators are compared by evaluating a series of
|
-- random numbers they produce. A matching series of random numbers
|
-- random numbers they produce. A matching series of random numbers
|
-- implies that the generators were in the same state prior to producing
|
-- implies that the generators were in the same state prior to producing
|
-- the numbers.
|
-- the numbers.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 20 Apr 95 SAIC Initial prerelease version.
|
-- 20 Apr 95 SAIC Initial prerelease version.
|
-- 07 Jul 95 SAIC Incorporated reviewer comments/suggestions.
|
-- 07 Jul 95 SAIC Incorporated reviewer comments/suggestions.
|
-- 22 Apr 96 SAIC Incorporated reviewer comments for ACVC 2.1.
|
-- 22 Apr 96 SAIC Incorporated reviewer comments for ACVC 2.1.
|
-- 17 Aug 96 SAIC Deleted Subtest #2.
|
-- 17 Aug 96 SAIC Deleted Subtest #2.
|
-- 09 Feb 01 RLB Repaired to work on implementations with a 16-bit
|
-- 09 Feb 01 RLB Repaired to work on implementations with a 16-bit
|
-- Integer.
|
-- Integer.
|
|
|
--!
|
--!
|
|
|
with Ada.Exceptions;
|
with Ada.Exceptions;
|
with Ada.Numerics.Float_Random;
|
with Ada.Numerics.Float_Random;
|
with Ada.Numerics.Discrete_Random;
|
with Ada.Numerics.Discrete_Random;
|
with Ada.Strings.Bounded;
|
with Ada.Strings.Bounded;
|
with ImpDef;
|
with ImpDef;
|
with Report;
|
with Report;
|
|
|
procedure CXA5011 is
|
procedure CXA5011 is
|
begin
|
begin
|
|
|
Report.Test ("CXA5011", "Check the effect of Function Reset on the " &
|
Report.Test ("CXA5011", "Check the effect of Function Reset on the " &
|
"state of random number generators");
|
"state of random number generators");
|
|
|
Test_Block:
|
Test_Block:
|
declare
|
declare
|
|
|
use Ada.Exceptions;
|
use Ada.Exceptions;
|
use Ada.Numerics;
|
use Ada.Numerics;
|
use Ada.Strings.Bounded;
|
use Ada.Strings.Bounded;
|
|
|
-- Declare an modular subtype, and use it to instantiate the discrete
|
-- Declare an modular subtype, and use it to instantiate the discrete
|
-- random number generator generic package.
|
-- random number generator generic package.
|
|
|
type Discrete_Range is mod 2**(Integer'Size-1);
|
type Discrete_Range is mod 2**(Integer'Size-1);
|
package Discrete_Package is new Discrete_Random(Discrete_Range);
|
package Discrete_Package is new Discrete_Random(Discrete_Range);
|
|
|
-- Declaration of random number generator objects.
|
-- Declaration of random number generator objects.
|
|
|
Discrete_Generator_1,
|
Discrete_Generator_1,
|
Discrete_Generator_2 : Discrete_Package.Generator;
|
Discrete_Generator_2 : Discrete_Package.Generator;
|
Float_Generator_1,
|
Float_Generator_1,
|
Float_Generator_2 : Float_Random.Generator;
|
Float_Generator_2 : Float_Random.Generator;
|
|
|
-- Declaration of bounded string packages instantiated with the
|
-- Declaration of bounded string packages instantiated with the
|
-- value of Max_Image_Width constant from each random number generator
|
-- value of Max_Image_Width constant from each random number generator
|
-- package, and bounded string variables used to hold the image of
|
-- package, and bounded string variables used to hold the image of
|
-- random number generator states.
|
-- random number generator states.
|
|
|
package Discrete_String_Pack is
|
package Discrete_String_Pack is
|
new Generic_Bounded_Length(Discrete_Package.Max_Image_Width);
|
new Generic_Bounded_Length(Discrete_Package.Max_Image_Width);
|
|
|
package Float_String_Pack is
|
package Float_String_Pack is
|
new Generic_Bounded_Length(Float_Random.Max_Image_Width);
|
new Generic_Bounded_Length(Float_Random.Max_Image_Width);
|
|
|
use Discrete_String_Pack, Float_String_Pack;
|
use Discrete_String_Pack, Float_String_Pack;
|
|
|
TC_Seed : Integer;
|
TC_Seed : Integer;
|
TC_Max_Loop_Count : constant Natural := 1000;
|
TC_Max_Loop_Count : constant Natural := 1000;
|
Allowed_Matches : constant Natural := 2;
|
Allowed_Matches : constant Natural := 2;
|
--
|
--
|
-- In a sequence of TC_Max_Loop_Count random numbers that should
|
-- In a sequence of TC_Max_Loop_Count random numbers that should
|
-- not match, some may match by chance. Up to Allowed_Matches
|
-- not match, some may match by chance. Up to Allowed_Matches
|
-- numbers may match before the test is considered to fail.
|
-- numbers may match before the test is considered to fail.
|
--
|
--
|
|
|
|
|
procedure Check_Float_State (Gen_1, Gen_2 : Float_Random.Generator;
|
procedure Check_Float_State (Gen_1, Gen_2 : Float_Random.Generator;
|
Sub_Test : Integer;
|
Sub_Test : Integer;
|
States_Should_Match : Boolean) is
|
States_Should_Match : Boolean) is
|
|
|
use type Float_Random.State;
|
use type Float_Random.State;
|
|
|
State_1,
|
State_1,
|
State_2 : Float_Random.State;
|
State_2 : Float_Random.State;
|
|
|
State_String_1,
|
State_String_1,
|
State_String_2 : Float_String_Pack.Bounded_String :=
|
State_String_2 : Float_String_Pack.Bounded_String :=
|
Float_String_Pack.Null_Bounded_String;
|
Float_String_Pack.Null_Bounded_String;
|
begin
|
begin
|
|
|
Float_Random.Save(Gen => Gen_1, To_State => State_1);
|
Float_Random.Save(Gen => Gen_1, To_State => State_1);
|
Float_Random.Save(Gen_2, State_2);
|
Float_Random.Save(Gen_2, State_2);
|
|
|
State_String_1 :=
|
State_String_1 :=
|
Float_String_Pack.To_Bounded_String(Source =>
|
Float_String_Pack.To_Bounded_String(Source =>
|
Float_Random.Image(Of_State => State_1));
|
Float_Random.Image(Of_State => State_1));
|
|
|
State_String_2 :=
|
State_String_2 :=
|
Float_String_Pack.To_Bounded_String(Float_Random.Image(State_2));
|
Float_String_Pack.To_Bounded_String(Float_Random.Image(State_2));
|
|
|
case States_Should_Match is
|
case States_Should_Match is
|
when True =>
|
when True =>
|
if State_1 /= State_2 then
|
if State_1 /= State_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State values from Float generators " &
|
" State values from Float generators " &
|
"are not the same");
|
"are not the same");
|
end if;
|
end if;
|
if State_String_1 /= State_String_2 then
|
if State_String_1 /= State_String_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State strings from Float generators " &
|
" State strings from Float generators " &
|
"are not the same");
|
"are not the same");
|
end if;
|
end if;
|
when False =>
|
when False =>
|
if State_1 = State_2 then
|
if State_1 = State_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State values from Float generators " &
|
" State values from Float generators " &
|
"are the same");
|
"are the same");
|
end if;
|
end if;
|
if State_String_1 = State_String_2 then
|
if State_String_1 = State_String_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State strings from Float generators " &
|
" State strings from Float generators " &
|
"are the same");
|
"are the same");
|
end if;
|
end if;
|
end case;
|
end case;
|
end Check_Float_State;
|
end Check_Float_State;
|
|
|
|
|
|
|
procedure Check_Discrete_State (Gen_1,
|
procedure Check_Discrete_State (Gen_1,
|
Gen_2 : Discrete_Package.Generator;
|
Gen_2 : Discrete_Package.Generator;
|
Sub_Test : Integer;
|
Sub_Test : Integer;
|
States_Should_Match : Boolean) is
|
States_Should_Match : Boolean) is
|
|
|
use type Discrete_Package.State;
|
use type Discrete_Package.State;
|
|
|
State_1, State_2 : Discrete_Package.State;
|
State_1, State_2 : Discrete_Package.State;
|
|
|
State_String_1,
|
State_String_1,
|
State_String_2 : Discrete_String_Pack.Bounded_String :=
|
State_String_2 : Discrete_String_Pack.Bounded_String :=
|
Discrete_String_Pack.Null_Bounded_String;
|
Discrete_String_Pack.Null_Bounded_String;
|
begin
|
begin
|
|
|
Discrete_Package.Save(Gen => Gen_1,
|
Discrete_Package.Save(Gen => Gen_1,
|
To_State => State_1);
|
To_State => State_1);
|
Discrete_Package.Save(Gen_2, To_State => State_2);
|
Discrete_Package.Save(Gen_2, To_State => State_2);
|
|
|
State_String_1 :=
|
State_String_1 :=
|
Discrete_String_Pack.To_Bounded_String(Source =>
|
Discrete_String_Pack.To_Bounded_String(Source =>
|
Discrete_Package.Image(Of_State => State_1));
|
Discrete_Package.Image(Of_State => State_1));
|
|
|
State_String_2 :=
|
State_String_2 :=
|
Discrete_String_Pack.To_Bounded_String(Source =>
|
Discrete_String_Pack.To_Bounded_String(Source =>
|
Discrete_Package.Image(Of_State => State_2));
|
Discrete_Package.Image(Of_State => State_2));
|
|
|
case States_Should_Match is
|
case States_Should_Match is
|
when True =>
|
when True =>
|
if State_1 /= State_2 then
|
if State_1 /= State_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State values from Discrete " &
|
" State values from Discrete " &
|
"generators are not the same");
|
"generators are not the same");
|
end if;
|
end if;
|
if State_String_1 /= State_String_2 then
|
if State_String_1 /= State_String_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State strings from Discrete " &
|
" State strings from Discrete " &
|
"generators are not the same");
|
"generators are not the same");
|
end if;
|
end if;
|
when False =>
|
when False =>
|
if State_1 = State_2 then
|
if State_1 = State_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State values from Discrete " &
|
" State values from Discrete " &
|
"generators are the same");
|
"generators are the same");
|
end if;
|
end if;
|
if State_String_1 = State_String_2 then
|
if State_String_1 = State_String_2 then
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
Report.Failed("Subtest #" & Integer'Image(Sub_Test) &
|
" State strings from Discrete " &
|
" State strings from Discrete " &
|
"generators are the same");
|
"generators are the same");
|
end if;
|
end if;
|
end case;
|
end case;
|
end Check_Discrete_State;
|
end Check_Discrete_State;
|
|
|
|
|
|
|
procedure Check_Float_Values (Gen_1, Gen_2 : Float_Random.Generator;
|
procedure Check_Float_Values (Gen_1, Gen_2 : Float_Random.Generator;
|
Sub_Test : Integer;
|
Sub_Test : Integer;
|
Values_Should_Match : Boolean) is
|
Values_Should_Match : Boolean) is
|
Matches : Natural := 0;
|
Matches : Natural := 0;
|
Check_Failed : Boolean := False;
|
Check_Failed : Boolean := False;
|
begin
|
begin
|
case Values_Should_Match is
|
case Values_Should_Match is
|
when True =>
|
when True =>
|
for i in 1..TC_Max_Loop_Count loop
|
for i in 1..TC_Max_Loop_Count loop
|
if Float_Random.Random(Gen_1) /= Float_Random.Random(Gen_2)
|
if Float_Random.Random(Gen_1) /= Float_Random.Random(Gen_2)
|
then
|
then
|
Check_Failed := True;
|
Check_Failed := True;
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
if Check_Failed then
|
if Check_Failed then
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
" Random numbers from Float generators " &
|
" Random numbers from Float generators " &
|
"Failed check");
|
"Failed check");
|
end if;
|
end if;
|
when False =>
|
when False =>
|
for i in 1..TC_Max_Loop_Count loop
|
for i in 1..TC_Max_Loop_Count loop
|
if Float_Random.Random(Gen_1) = Float_Random.Random(Gen_2)
|
if Float_Random.Random(Gen_1) = Float_Random.Random(Gen_2)
|
then
|
then
|
Matches := Matches + 1;
|
Matches := Matches + 1;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end case;
|
end case;
|
|
|
if (Values_Should_Match and Check_Failed) or
|
if (Values_Should_Match and Check_Failed) or
|
(not Values_Should_Match and Matches > Allowed_Matches)
|
(not Values_Should_Match and Matches > Allowed_Matches)
|
then
|
then
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
" Random numbers from Float generators " &
|
" Random numbers from Float generators " &
|
"Failed check");
|
"Failed check");
|
end if;
|
end if;
|
|
|
end Check_Float_Values;
|
end Check_Float_Values;
|
|
|
|
|
|
|
procedure Check_Discrete_Values (Gen_1,
|
procedure Check_Discrete_Values (Gen_1,
|
Gen_2 : Discrete_Package.Generator;
|
Gen_2 : Discrete_Package.Generator;
|
Sub_Test : Integer;
|
Sub_Test : Integer;
|
Values_Should_Match : Boolean) is
|
Values_Should_Match : Boolean) is
|
Matches : Natural := 0;
|
Matches : Natural := 0;
|
Check_Failed : Boolean := False;
|
Check_Failed : Boolean := False;
|
begin
|
begin
|
case Values_Should_Match is
|
case Values_Should_Match is
|
when True =>
|
when True =>
|
for i in 1..TC_Max_Loop_Count loop
|
for i in 1..TC_Max_Loop_Count loop
|
if Discrete_Package.Random(Gen_1) /=
|
if Discrete_Package.Random(Gen_1) /=
|
Discrete_Package.Random(Gen_2)
|
Discrete_Package.Random(Gen_2)
|
then
|
then
|
Check_Failed := True;
|
Check_Failed := True;
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
when False =>
|
when False =>
|
for i in 1..TC_Max_Loop_Count loop
|
for i in 1..TC_Max_Loop_Count loop
|
if Discrete_Package.Random(Gen_1) =
|
if Discrete_Package.Random(Gen_1) =
|
Discrete_Package.Random(Gen_2)
|
Discrete_Package.Random(Gen_2)
|
then
|
then
|
Matches := Matches + 1;
|
Matches := Matches + 1;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
end case;
|
end case;
|
|
|
if (Values_Should_Match and Check_Failed) or
|
if (Values_Should_Match and Check_Failed) or
|
(not Values_Should_Match and Matches > Allowed_Matches)
|
(not Values_Should_Match and Matches > Allowed_Matches)
|
then
|
then
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
Report.Failed("Sub_Test # " & Integer'Image(Sub_Test) &
|
" Random numbers from Discrete generators " &
|
" Random numbers from Discrete generators " &
|
"Failed check");
|
"Failed check");
|
end if;
|
end if;
|
|
|
end Check_Discrete_Values;
|
end Check_Discrete_Values;
|
|
|
|
|
|
|
begin
|
begin
|
|
|
Sub_Test_1:
|
Sub_Test_1:
|
-- Check that two objects of type Generator are initialized to the
|
-- Check that two objects of type Generator are initialized to the
|
-- same state.
|
-- same state.
|
begin
|
begin
|
|
|
-- Since the discrete and float random generators are in the initial
|
-- Since the discrete and float random generators are in the initial
|
-- state, using Procedure Save to save the states of the generator
|
-- state, using Procedure Save to save the states of the generator
|
-- objects, and transforming these states into strings using
|
-- objects, and transforming these states into strings using
|
-- Function Image, should yield identical strings.
|
-- Function Image, should yield identical strings.
|
|
|
Check_Discrete_State (Discrete_Generator_1,
|
Check_Discrete_State (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 1,
|
Sub_Test => 1,
|
States_Should_Match => True);
|
States_Should_Match => True);
|
|
|
Check_Float_State (Float_Generator_1,
|
Check_Float_State (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 1,
|
Sub_Test => 1,
|
States_Should_Match => True);
|
States_Should_Match => True);
|
|
|
-- Since the two random generator objects are in their initial
|
-- Since the two random generator objects are in their initial
|
-- state, the values produced from each (upon calls to Random)
|
-- state, the values produced from each (upon calls to Random)
|
-- should be identical.
|
-- should be identical.
|
|
|
Check_Discrete_Values (Discrete_Generator_1,
|
Check_Discrete_Values (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 1,
|
Sub_Test => 1,
|
Values_Should_Match => True);
|
Values_Should_Match => True);
|
|
|
Check_Float_Values (Float_Generator_1,
|
Check_Float_Values (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 1,
|
Sub_Test => 1,
|
Values_Should_Match => True);
|
Values_Should_Match => True);
|
|
|
end Sub_Test_1;
|
end Sub_Test_1;
|
|
|
|
|
|
|
Sub_Test_3:
|
Sub_Test_3:
|
-- Check that when the Function Reset uses the same integer
|
-- Check that when the Function Reset uses the same integer
|
-- initiator to reset two generators to the same state, the
|
-- initiator to reset two generators to the same state, the
|
-- resulting random values and the state from each generator
|
-- resulting random values and the state from each generator
|
-- are identical.
|
-- are identical.
|
declare
|
declare
|
use Discrete_Package, Float_Random;
|
use Discrete_Package, Float_Random;
|
begin
|
begin
|
|
|
-- Reset the generators to the same states, using the version of
|
-- Reset the generators to the same states, using the version of
|
-- Function Reset with both generator parameter and initiator
|
-- Function Reset with both generator parameter and initiator
|
-- specified.
|
-- specified.
|
|
|
TC_Seed := Integer(Random(Discrete_Generator_1));
|
TC_Seed := Integer(Random(Discrete_Generator_1));
|
Reset(Gen => Discrete_Generator_1, Initiator => TC_Seed);
|
Reset(Gen => Discrete_Generator_1, Initiator => TC_Seed);
|
Reset(Discrete_Generator_2, Initiator => TC_Seed);
|
Reset(Discrete_Generator_2, Initiator => TC_Seed);
|
Reset(Float_Generator_1, TC_Seed);
|
Reset(Float_Generator_1, TC_Seed);
|
Reset(Float_Generator_2, TC_Seed);
|
Reset(Float_Generator_2, TC_Seed);
|
|
|
-- Since the random generators have been reset to identical states,
|
-- Since the random generators have been reset to identical states,
|
-- bounded string images of these states should yield identical
|
-- bounded string images of these states should yield identical
|
-- strings.
|
-- strings.
|
|
|
Check_Discrete_State (Discrete_Generator_1,
|
Check_Discrete_State (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 3,
|
Sub_Test => 3,
|
States_Should_Match => True);
|
States_Should_Match => True);
|
|
|
Check_Float_State (Float_Generator_1,
|
Check_Float_State (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 3,
|
Sub_Test => 3,
|
States_Should_Match => True);
|
States_Should_Match => True);
|
|
|
-- Since the random generators have been reset to identical states,
|
-- Since the random generators have been reset to identical states,
|
-- the values produced from each (upon calls to Random) should
|
-- the values produced from each (upon calls to Random) should
|
-- be identical.
|
-- be identical.
|
|
|
Check_Discrete_Values (Discrete_Generator_1,
|
Check_Discrete_Values (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 3,
|
Sub_Test => 3,
|
Values_Should_Match => True);
|
Values_Should_Match => True);
|
|
|
Check_Float_Values (Float_Generator_1,
|
Check_Float_Values (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 3,
|
Sub_Test => 3,
|
Values_Should_Match => True);
|
Values_Should_Match => True);
|
|
|
end Sub_Test_3;
|
end Sub_Test_3;
|
|
|
|
|
|
|
Sub_Test_4:
|
Sub_Test_4:
|
-- Check that when the Function Reset uses different integer
|
-- Check that when the Function Reset uses different integer
|
-- initiator values to reset two generators, the resulting random
|
-- initiator values to reset two generators, the resulting random
|
-- numbers and states are different.
|
-- numbers and states are different.
|
begin
|
begin
|
|
|
-- Reset the generators to different states.
|
-- Reset the generators to different states.
|
|
|
TC_Seed :=
|
TC_Seed :=
|
Integer(Discrete_Package.Random(Discrete_Generator_1));
|
Integer(Discrete_Package.Random(Discrete_Generator_1));
|
|
|
Discrete_Package.Reset(Gen => Discrete_Generator_1,
|
Discrete_Package.Reset(Gen => Discrete_Generator_1,
|
Initiator => TC_Seed);
|
Initiator => TC_Seed);
|
|
|
-- Set the seed value to a different value for the second call
|
-- Set the seed value to a different value for the second call
|
-- to Reset.
|
-- to Reset.
|
-- Note: A second call to Random could be made, as above, but that
|
-- Note: A second call to Random could be made, as above, but that
|
-- would not ensure that the resulting seed value was
|
-- would not ensure that the resulting seed value was
|
-- different from the first.
|
-- different from the first.
|
|
|
if TC_Seed /= Integer'Last then
|
if TC_Seed /= Integer'Last then
|
TC_Seed := TC_Seed + 1;
|
TC_Seed := TC_Seed + 1;
|
else
|
else
|
TC_Seed := TC_Seed - 1;
|
TC_Seed := TC_Seed - 1;
|
end if;
|
end if;
|
|
|
Discrete_Package.Reset(Gen => Discrete_Generator_2,
|
Discrete_Package.Reset(Gen => Discrete_Generator_2,
|
Initiator => TC_Seed);
|
Initiator => TC_Seed);
|
|
|
Float_Random.Reset(Float_Generator_1, 16#FF#); -- 255
|
Float_Random.Reset(Float_Generator_1, 16#FF#); -- 255
|
Float_Random.Reset(Float_Generator_2, 2#1110_0000#); -- 224
|
Float_Random.Reset(Float_Generator_2, 2#1110_0000#); -- 224
|
|
|
-- Since the two float random generators are in different
|
-- Since the two float random generators are in different
|
-- states, the bounded string images depicting their states should
|
-- states, the bounded string images depicting their states should
|
-- differ.
|
-- differ.
|
|
|
Check_Discrete_State (Discrete_Generator_1,
|
Check_Discrete_State (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 4,
|
Sub_Test => 4,
|
States_Should_Match => False);
|
States_Should_Match => False);
|
|
|
Check_Float_State (Float_Generator_1,
|
Check_Float_State (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 4,
|
Sub_Test => 4,
|
States_Should_Match => False);
|
States_Should_Match => False);
|
|
|
-- Since the two discrete random generator objects were reset
|
-- Since the two discrete random generator objects were reset
|
-- to different states, the values produced from each (upon calls
|
-- to different states, the values produced from each (upon calls
|
-- to Random) should differ.
|
-- to Random) should differ.
|
|
|
Check_Discrete_Values (Discrete_Generator_1,
|
Check_Discrete_Values (Discrete_Generator_1,
|
Discrete_Generator_2,
|
Discrete_Generator_2,
|
Sub_Test => 4,
|
Sub_Test => 4,
|
Values_Should_Match => False);
|
Values_Should_Match => False);
|
|
|
Check_Float_Values (Float_Generator_1,
|
Check_Float_Values (Float_Generator_1,
|
Float_Generator_2,
|
Float_Generator_2,
|
Sub_Test => 4,
|
Sub_Test => 4,
|
Values_Should_Match => False);
|
Values_Should_Match => False);
|
|
|
end Sub_Test_4;
|
end Sub_Test_4;
|
|
|
exception
|
exception
|
when The_Error : others =>
|
when The_Error : others =>
|
Report.Failed ("The following exception was raised in the " &
|
Report.Failed ("The following exception was raised in the " &
|
"Test_Block: " & Exception_Name(The_Error));
|
"Test_Block: " & Exception_Name(The_Error));
|
end Test_Block;
|
end Test_Block;
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end CXA5011;
|
end CXA5011;
|
|
|