cxa5012.a
来自「xml大全 可读写调用率很高 xml大全 可读写调用率很高」· A 代码 · 共 537 行 · 第 1/2 页
A
537 行
TC_Discrete_Check_Failed := False; end if; if TC_Enum_Check_Failed then Report.Failed("Enumeration random values generated following " & "use of procedures Save and Reset were not the " & "same"); TC_Enum_Check_Failed := False; end if; if TC_Float_Check_Failed then Report.Failed("Float random values generated following use " & "of procedures Save and Reset were not the same"); TC_Float_Check_Failed := False; end if; end Objective_1; Objective_2: -- Check that the Function Image can be used to obtain a string -- representation of the state of a generator. -- Check that the Function Value will transform a string -- representation of the state of a random number generator -- into the actual state object. begin -- Use two discrete and float random number generators to generate -- a series of values (so that the generators are no longer in their -- initial states, and they have generated the same number of -- random values). TC_Seed := Integer(Discrete_Pack.Random(DGen_1)); Discrete_Pack.Reset(DGen_1, TC_Seed); Discrete_Pack.Reset(DGen_2, TC_Seed); Card_Pack.Reset (EGen_1, TC_Seed); Card_Pack.Reset (EGen_2, TC_Seed); Float_Random.Reset (FGen_1, TC_Seed); Float_Random.Reset (FGen_2, TC_Seed); for i in 1..1000 loop DVal_1 := Discrete_Pack.Random(DGen_1); DVal_2 := Discrete_Pack.Random(DGen_2); EVal_1 := Card_Pack.Random(EGen_1); EVal_2 := Card_Pack.Random(EGen_2); FVal_1 := Float_Random.Random(FGen_1); FVal_2 := Float_Random.Random(FGen_2); end loop; -- Use the Procedure Save to save the states of the generators -- to state variables. Discrete_Pack.Save(Gen => DGen_1, To_State => DState_1); Discrete_Pack.Save(DGen_2, To_State => DState_2); Card_Pack.Save (Gen => EGen_1, To_State => EState_1); Card_Pack.Save (EGen_2, To_State => EState_2); Float_Random.Save (FGen_1, To_State => FState_1); Float_Random.Save (FGen_2, FState_2); -- Use the Function Image to produce a representation of the state -- codes as (bounded) string objects. DString_1 := DString_Pack.To_Bounded_String( Discrete_Pack.Image(Of_State => DState_1)); DString_2 := DString_Pack.To_Bounded_String( Discrete_Pack.Image(DState_2)); EString_1 := EString_Pack.To_Bounded_String( Card_Pack.Image(Of_State => EState_1)); EString_2 := EString_Pack.To_Bounded_String( Card_Pack.Image(EState_2)); FString_1 := FString_Pack.To_Bounded_String( Float_Random.Image(Of_State => FState_1)); FString_2 := FString_Pack.To_Bounded_String( Float_Random.Image(FState_2)); -- Compare the bounded string objects for equality. if DString_1 /= DString_2 then Report.Failed("String values returned from Function Image " & "depict different states of Discrete generators"); end if; if EString_1 /= EString_2 then Report.Failed("String values returned from Function Image " & "depict different states of Enumeration " & "generators"); end if; if FString_1 /= FString_2 then Report.Failed("String values returned from Function Image " & "depict different states of Float generators"); end if; -- The string representation of a state code is transformed back -- to a state code variable using the Function Value. DState_1 := Discrete_Pack.Value(Coded_State => DString_Pack.To_String(DString_1)); EState_1 := Card_Pack.Value(EString_Pack.To_String(EString_1)); FState_1 := Float_Random.Value(FString_Pack.To_String(FString_1)); -- One of the (pair of each type of ) generators is used to generate -- a series of random values, getting them "out of synch" with the -- specific generation sequence of the other generators. for i in 1..100 loop DVal_1 := Discrete_Pack.Random(DGen_1); EVal_1 := Card_Pack.Random(EGen_1); FVal_1 := Float_Random.Random (FGen_1); end loop; -- The "out of synch" generators are reset to the previous state they -- had when their states were saved, and they should now have the same -- states as the generators that did not generate the values above. Discrete_Pack.Reset(Gen => DGen_1, From_State => DState_1); Card_Pack.Reset (Gen => EGen_1, From_State => EState_1); Float_Random.Reset (Gen => FGen_1, From_State => FState_1); -- All generators should now be in the same state, so the -- random values they produce should be the same. for i in 1..1000 loop if Discrete_Pack.Random(DGen_1) /= Discrete_Pack.Random(DGen_2) then TC_Discrete_Check_Failed := True; exit; end if; end loop; for i in 1..1000 loop if Card_Pack.Random(EGen_1) /= Card_Pack.Random(EGen_2) then TC_Enum_Check_Failed := True; exit; end if; end loop; for i in 1..1000 loop if Float_Random.Random(FGen_1) /= Float_Random.Random(FGen_2) then TC_Float_Check_Failed := True; exit; end if; end loop; if TC_Discrete_Check_Failed then Report.Failed("Random values generated following use of " & "procedures Image and Value were not the same " & "for Discrete generator"); end if; if TC_Enum_Check_Failed then Report.Failed("Random values generated following use of " & "procedures Image and Value were not the same " & "for Enumeration generator"); end if; if TC_Float_Check_Failed then Report.Failed("Random values generated following use of " & "procedures Image and Value were not the same " & "for Float generator"); end if; end Objective_2; Objective_3: -- Check that a call to Function Value, with a string value that is -- not the image of any generator state, is a bounded error. This -- error either raises Constraint_Error or Program_Error, or is -- accepted. (See Technical Corrigendum 1). declare Not_A_State : constant String := ImpDef.Non_State_String; begin begin DState_1 := Discrete_Pack.Value(Not_A_State); if Not_A_State /= "**NONE**" then Report.Failed("Exception not raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); else Report.Comment("All strings represent states for Function " & "Ada.Numerics.Discrete_Random.Value"); end if; Discrete_Pack.Reset(DGen_1, DState_1); exception when Constraint_Error => null; -- OK, expected exception. Report.Comment("Constraint_Error raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); when Program_Error => -- OK, expected exception. Report.Comment("Program_Error raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); when others => Report.Failed("Unexpected exception raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); end; begin EState_1 := Card_Pack.Value(Not_A_State); if Not_A_State /= "**NONE**" then Report.Failed("Exception not raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of an enumeration " & "random number generator"); else Report.Comment("All strings represent states for Function " & "Ada.Numerics.Discrete_Random.Value"); end if; Card_Pack.Reset(EGen_1, EState_1); exception when Constraint_Error => null; -- OK, expected exception. when Program_Error => null; -- OK, expected exception. when others => Report.Failed("Unexpected exception raised by Function " & "Ada.Numerics.Discrete_Random.Value when " & "provided a string input that does not " & "represent the state of an enumeration " & "random number generator"); end; begin FState_1 := Float_Random.Value(Not_A_State); if Not_A_State /= "**NONE**" then Report.Failed("Exception not raised by an " & "instantiated version of " & "Ada.Numerics.Float_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); else Report.Comment("All strings represent states for Function " & "Ada.Numerics.Float_Random.Value"); end if; Float_Random.Reset(FGen_1, FState_1); exception when Constraint_Error => null; -- OK, expected exception. when Program_Error => null; -- OK, expected exception. when others => Report.Failed("Unexpected exception raised by an " & "instantiated version of " & "Ada.Numerics.Float_Random.Value when " & "provided a string input that does not " & "represent the state of a random number " & "generator"); end; end Objective_3; exception when others => Report.Failed ("Exception raised in Test_Block"); end Test_Block; Report.Result;end CXA5012;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?