text stringlengths 0 234 |
|---|
begin |
Append_From_Query (Result, Stmt); |
T.Assert (Result.Length > 0, "The list should not be empty"); |
for I in 1 .. Result.Length loop |
declare |
Item : constant ASF.Models.Selects.Select_Item := Result.Get_Select_Item (I); |
begin |
-- The SQL query will return two different columns. |
-- Just check that label and values are different. |
T.Assert (Item.Get_Value /= Item.Get_Label, "Item and label are equals"); |
-- To make this test simple, check only for one known entry in the list. |
if Item.Get_Label = "awa_user" then |
Found_User := True; |
end if; |
Function Definition: procedure Day02 is |
Function Body: package ASU renames Ada.Strings.Unbounded; |
-- for convenience purpose |
type US_Array is array(Positive range <>) of ASU.Unbounded_String; |
-- The IDs in the input data are all the same length, so we could use a |
-- fixed-length String array, but it would not be very generic, and it would |
-- not be suited for examples either. |
type Natural_Couple is array(1..2) of Natural; |
-- This data structure will be used to store two things: |
-- * IDs that have exactly 2 of any letter and exactly 3 of any letter; |
-- * the absolute count of IDs for the previous item. |
-- I could/should use a record for that, but meh, later maybe. |
type Character_Count is array(Character range 'a' .. 'z') of Natural; |
-- An array indexed on characters that will be used to count occurrences. |
-- This is not very generic (cough), but it will do for the input. |
-- Creates the "String" array from the file name |
function Read_Input(file_name : in String) return US_Array is |
-- Tail-call recursion to create the final array. |
function Read_Input_Rec(input : in Ada.Text_IO.File_Type; acc : in US_Array) return US_Array is |
begin |
if Ada.Text_IO.End_Of_File(input) then |
return acc; |
else |
return Read_Input_Rec |
( |
input, |
acc & (1 => ASU.To_Unbounded_String(Ada.Text_IO.Get_Line(input))) |
); |
end if; |
end Read_Input_Rec; |
F : Ada.Text_IO.File_Type; |
acc : US_Array(1 .. 0); |
begin |
Ada.Text_IO.Open |
( |
File => F, |
Mode => Ada.Text_IO.In_File, |
Name => file_name |
); |
declare |
result : US_Array := Read_Input_Rec(F, acc); |
begin |
Ada.Text_IO.Close(F); |
return result; |
Function Definition: procedure Day01 is |
Function Body: type Integer_Array is array(Positive range <>) of Integer; |
-- The data structure to store the input. |
function Hash is new Ada.Unchecked_Conversion |
( |
Source => Integer, |
Target => Ada.Containers.Hash_Type |
); |
-- Creates a hash value from integers. |
-- Supposes that integers and Hash_Type have the same size. |
package Integer_Sets is new Ada.Containers.Hashed_Sets |
( |
Element_Type => Integer, |
Hash => Hash, |
Equivalent_Elements => "=" |
); |
-- For part 2: using a set to store frequencies. |
-- Creates the integer array from the name of the input file. |
function Read_Input(file_name : in String) return Integer_Array is |
-- Tail-call recursion to create the array of Integers. |
-- Using an accumulator allows to generate arbitrary length arrays. |
function Read_Input_Rec(input : in Ada.Text_IO.File_Type; acc : in Integer_Array) return Integer_Array is |
begin |
-- The stop condition. |
-- Not using End_Of_File will make the compiler issue a warning, which |
-- can prevent you from running the code if -Werror flag is enabled. |
if Ada.Text_IO.End_Of_File(input) then |
return acc; |
else |
return Read_Input_Rec |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.