cxa5011.a

来自「linux下编程用 编译软件」· A 代码 · 共 472 行 · 第 1/2 页

A
472
字号
            when True  =>               for i in 1..TC_Max_Loop_Count loop                  if Float_Random.Random(Gen_1) /= Float_Random.Random(Gen_2)                  then                     Check_Failed := True;                     exit;                  end if;               end loop;               if Check_Failed then                  Report.Failed("Sub_Test # " & Integer'Image(Sub_Test)    &                                "   Random numbers from Float generators " &                                "Failed check");               end if;            when False =>               for i in 1..TC_Max_Loop_Count loop                  if Float_Random.Random(Gen_1) = Float_Random.Random(Gen_2)                  then                     Matches := Matches + 1;                  end if;               end loop;         end case;         if (Values_Should_Match and Check_Failed) or            (not Values_Should_Match and Matches > Allowed_Matches)         then            Report.Failed("Sub_Test # " & Integer'Image(Sub_Test)    &                          "   Random numbers from Float generators " &                          "Failed check");         end if;      end Check_Float_Values;      procedure Check_Discrete_Values (Gen_1,                                       Gen_2    : Discrete_Package.Generator;                                       Sub_Test : Integer;                                       Values_Should_Match : Boolean) is         Matches         : Natural := 0;         Check_Failed    : Boolean := False;      begin         case Values_Should_Match is            when True  =>               for i in 1..TC_Max_Loop_Count loop                  if Discrete_Package.Random(Gen_1) /=                     Discrete_Package.Random(Gen_2)                  then                     Check_Failed := True;                     exit;                  end if;               end loop;            when False =>               for i in 1..TC_Max_Loop_Count loop                  if Discrete_Package.Random(Gen_1) =                     Discrete_Package.Random(Gen_2)                  then                     Matches := Matches + 1;                  end if;               end loop;         end case;         if (Values_Should_Match and Check_Failed) or            (not Values_Should_Match and Matches > Allowed_Matches)         then            Report.Failed("Sub_Test # " & Integer'Image(Sub_Test)    &                          "   Random numbers from Discrete generators " &                          "Failed check");         end if;      end Check_Discrete_Values;   begin      Sub_Test_1:         -- Check that two objects of type Generator are initialized to the         -- same state.      begin         -- Since the discrete and float random generators are in the initial         -- state, using Procedure Save to save the states of the generator         -- objects, and transforming these states into strings using         -- Function Image, should yield identical strings.         Check_Discrete_State (Discrete_Generator_1,                               Discrete_Generator_2,                               Sub_Test => 1,                               States_Should_Match => True);         Check_Float_State (Float_Generator_1,                            Float_Generator_2,                            Sub_Test => 1,                            States_Should_Match => True);         -- Since the two random generator objects are in their initial         -- state, the values produced from each (upon calls to Random)         -- should be identical.         Check_Discrete_Values (Discrete_Generator_1,                                Discrete_Generator_2,                                Sub_Test => 1,                                Values_Should_Match => True);         Check_Float_Values (Float_Generator_1,                             Float_Generator_2,                             Sub_Test => 1,                             Values_Should_Match => True);      end Sub_Test_1;      Sub_Test_3:         -- Check that when the Function Reset uses the same integer         -- initiator to reset two generators to the same state, the         -- resulting random values and the state from each generator         -- are identical.      declare         use Discrete_Package, Float_Random;      begin         -- Reset the generators to the same states, using the version of         -- Function Reset with both generator parameter and initiator         -- specified.         TC_Seed := Integer(Random(Discrete_Generator_1));         Reset(Gen => Discrete_Generator_1, Initiator => TC_Seed);         Reset(Discrete_Generator_2, Initiator => TC_Seed);         Reset(Float_Generator_1, TC_Seed);         Reset(Float_Generator_2, TC_Seed);         -- Since the random generators have been reset to identical states,         -- bounded string images of these states should yield identical         -- strings.         Check_Discrete_State (Discrete_Generator_1,                               Discrete_Generator_2,                               Sub_Test => 3,                               States_Should_Match => True);         Check_Float_State (Float_Generator_1,                            Float_Generator_2,                            Sub_Test => 3,                            States_Should_Match => True);         -- Since the random generators have been reset to identical states,         -- the values produced from each (upon calls to Random) should         -- be identical.         Check_Discrete_Values (Discrete_Generator_1,                                Discrete_Generator_2,                                Sub_Test => 3,                                Values_Should_Match => True);         Check_Float_Values (Float_Generator_1,                             Float_Generator_2,                             Sub_Test => 3,                             Values_Should_Match => True);      end Sub_Test_3;      Sub_Test_4:         -- Check that when the Function Reset uses different integer         -- initiator values to reset two generators, the resulting random         -- numbers and states are different.      begin         -- Reset the generators to different states.         TC_Seed :=           Integer(Discrete_Package.Random(Discrete_Generator_1));         Discrete_Package.Reset(Gen       => Discrete_Generator_1,                                Initiator => TC_Seed);         -- Set the seed value to a different value for the second call         -- to Reset.         -- Note: A second call to Random could be made, as above, but that         --       would not ensure that the resulting seed value was         --       different from the first.         if TC_Seed /= Integer'Last then            TC_Seed := TC_Seed + 1;         else            TC_Seed := TC_Seed - 1;         end if;         Discrete_Package.Reset(Gen       => Discrete_Generator_2,                                Initiator => TC_Seed);         Float_Random.Reset(Float_Generator_1, 16#FF#);             -- 255         Float_Random.Reset(Float_Generator_2, 2#1110_0000#);       -- 224         -- Since the two float random generators are in different         -- states, the bounded string images depicting their states should         -- differ.         Check_Discrete_State (Discrete_Generator_1,                               Discrete_Generator_2,                               Sub_Test => 4,                               States_Should_Match => False);         Check_Float_State (Float_Generator_1,                            Float_Generator_2,                            Sub_Test => 4,                            States_Should_Match => False);         -- Since the two discrete random generator objects were reset         -- to different states, the values produced from each (upon calls         -- to Random) should differ.         Check_Discrete_Values (Discrete_Generator_1,                                Discrete_Generator_2,                                Sub_Test => 4,                                Values_Should_Match => False);         Check_Float_Values (Float_Generator_1,                             Float_Generator_2,                             Sub_Test => 4,                             Values_Should_Match => False);      end Sub_Test_4;   exception      when The_Error : others =>         Report.Failed ("The following exception was raised in the " &                        "Test_Block: " & Exception_Name(The_Error));   end Test_Block;   Report.Result;end CXA5011;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?