cxg1003.a
来自「linux下编程用 编译软件」· A 代码 · 共 479 行 · 第 1/2 页
A
479 行
"was used to read complex data with incorrect " & "syntax from the Data_File, data item #" & Integer'Image(i)); end; end loop; if TC_Verbose then Report.Comment("Erroneous set of complex values extracted " & "from data file using Complex_IO, " & "Procedure Process_Data_File"); end if; exception when others => Report.Failed ("Unexpected exception raised in Process_Data_File"); end Process_Data_File; begin -- Test_Block. -- Place complex values into data file. Load_Data_File(Data_File); Text_IO.Close(Data_File); if TC_Verbose then Report.Comment("Data file loaded with Complex values"); end if; -- Read complex values from data file. Text_IO.Open(Data_File, Text_IO.In_File, Data_Filename); Process_Data_File(Data_File); if TC_Verbose then Report.Comment("Complex values extracted from data file"); end if; -- Verify versions of Procedures Put and Get for Strings. declare TC_String_Array : array (1..Number_Of_Complex_Items) of String(1..15) := (others =>(others => ' ')); begin -- Place complex values into strings using the Procedure Put. for i in 1..Number_Of_Complex_Items loop C_IO.Put(To => TC_String_Array(i), Item => Complex_Array(i), Aft => 1, Exp => 0); end loop; if TC_Verbose then Report.Comment("Complex values placed into string array"); end if; -- Check the format of the strings containing a complex number. -- The resulting strings are of 15 character length, with the -- real component left justified within the string, followed by -- a comma, and with the imaginary component and closing -- parenthesis right justified in the string, with blank fill -- for the balance of the string. if TC_String_Array(1) /= "(3.0, 9.0)" or TC_String_Array(2) /= "(4.0, 7.0)" or TC_String_Array(3) /= "(5.0, 6.0)" or TC_String_Array(4) /= "(6.0, 3.0)" or TC_String_Array(5) /= "(2.0, 5.0)" or TC_String_Array(6) /= "(3.0, 7.0)" then Report.Failed("Incorrect format for complex values that " & "have been placed into string variables " & "using the Complex_IO.Put procedure for " & "strings"); end if; if TC_Verbose then Report.Comment("String format of Complex values verified"); end if; -- Get complex values from strings using the Procedure Get. -- Compare with expected complex values. for i in 1..Number_Of_Complex_Items loop C_IO.Get(From => TC_String_Array(i), Item => TC_Complex, Last => TC_Last_Character_Read); if TC_Complex /= Complex_Array(i) then Report.Failed("Incorrect complex data value obtained " & "from String following use of Procedures " & "Put and Get from Strings, Complex_Array " & "item #" & Integer'Image(i)); end if; end loop; if TC_Verbose then Report.Comment("Complex values removed from String array"); end if; -- Verify that Layout_Error is raised if the given string is -- too short to hold the formatted output. Layout_Error_On_Put: declare Much_Too_Short : String(1..2); Complex_Value : Complex_Pack.Complex := (5.0, 0.0); begin C_IO.Put(Much_Too_Short, Complex_Value); Report.Failed("Layout_Error not raised by Procedure Put " & "when the given string was too short to " & "hold the formatted output"); exception when Layout_Error => null; -- OK, expected exception. when others => Report.Failed ("Unexpected exception raised by Procedure Put when " & "the given string was too short to hold the " & "formatted output"); end Layout_Error_On_Put; if TC_Verbose then Report.Comment("Layout Errors verified"); end if; exception when others => Report.Failed("Unexpected exception raised during the " & "evaluation of Put and Get for Strings"); end; -- Place complex values into strings using a variety of legal -- complex data formats. declare type String_Ptr is access String; TC_Complex_String_Array : array (1..Number_Of_Complex_Items) of String_Ptr := (new String'( "(3.0, 9.0 )" ), new String'( "+4.0 +7.0" ), new String'( "(5.0 6.0)" ), new String'( "6.0, 3.0" ), new String'( " ( 2.0 , 5.0 ) " ), new String'( "(3.0 7.0)" )); -- The following array contains Positive values that correspond -- to the last character that will be read by Procedure Get when -- given each of the above strings as input. TC_Last_Char_Array : array (1..Number_Of_Complex_Items) of Positive := (12,10,9,8,20,22); begin -- Get complex values from strings using the Procedure Get. -- Compare with expected complex values. for i in 1..Number_Of_Complex_Items loop C_IO.Get(TC_Complex_String_Array(i).all, TC_Complex, TC_Last_Character_Read); if TC_Complex /= Complex_Array(i) then Report.Failed ("Incorrect complex data value obtained from " & "Procedure Get with complex data input of: " & TC_Complex_String_Array(i).all); end if; if TC_Last_Character_Read /= TC_Last_Char_Array(i) then Report.Failed ("Incorrect value returned as the last character of " & "the input string processed by Procedure Get, " & "string value : " & TC_Complex_String_Array(i).all & " expected last character value read : " & Positive'Image(TC_Last_Char_Array(i)) & " last character value read : " & Positive'Image(TC_Last_Character_Read)); end if; end loop; if TC_Verbose then Report.Comment("Complex values removed from strings and " & "verified against expected values"); end if; exception when others => Report.Failed("Unexpected exception raised during the " & "evaluation of Get for Strings"); end; exception when others => Report.Failed ("Exception raised in Test_Block"); end Test_Block; -- Delete the external file. if Ada.Text_IO.Is_Open(Data_File) then Ada.Text_IO.Delete(Data_File); else Ada.Text_IO.Open(Data_File, Ada.Text_IO.In_File, Data_Filename); Ada.Text_IO.Delete(Data_File); end if; exception -- Since Use_Error can be raised if, for the specified mode, -- the environment does not support Text_IO operations, the -- following handlers are included: when Ada.Text_IO.Use_Error => Report.Not_Applicable ("Use_Error raised on Text_IO Create"); when Ada.Text_IO.Name_Error => Report.Not_Applicable ("Name_Error raised on Text_IO Create"); when others => Report.Failed ("Unexpected exception raised on text file Create"); end Test_for_Text_IO_Support; Report.Result;end CXG1003;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?