package body Graph_Tests.Search is function Find_Check return Test_Result is function Node_Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array); function Edge_Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array); Copy_Graph : Graphs.Graph := My_Complex_Graph; begin if not Node_Perm (Copy_Graph.Find (Node_Label (+"LOL")), No_Nodes) or not Edge_Perm (Copy_Graph.Find (Edge_Label (+"KEK")), No_Edges) then return Fail; end if; Copy_Graph.Append_Label (2, Node_Label (+"LOL")); Copy_Graph.Append_Label (5, Node_Label (+"LOL")); Copy_Graph.Append_Label ((6, 5, 6), Edge_Label (+"KEK")); Copy_Graph.Append_Label ((7, 5, 7), Edge_Label (+"KEK")); Copy_Graph.Append_Label (10, Node_Label (+"KEK")); Copy_Graph.Append_Label ((4, 2, 4), Edge_Label (+"LOL")); if not Node_Perm (Copy_Graph.Find (Node_Label (+"LOL")), (2, 5)) or not Edge_Perm (Copy_Graph.Find (Edge_Label (+"KEK")), ((6, 5, 6), (7, 5, 7))) then return Fail; end if; return Pass; end Find_Check; function Find_Subgraph_Check return Test_Result is function Node_Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array); function Edge_Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array); Copy_Graph : Graphs.Graph := My_Complex_Graph; Position : Graphs.Cursor := Copy_Graph.To_Cursor (7); begin if not Node_Perm (Graphs.Find_In_Subgraph (Position, Node_Label (+"LOL")), No_Nodes) or not Edge_Perm (Graphs.Find_In_Subgraph (Position, Edge_Label (+"KEK")), No_Edges) then return Fail; end if; Copy_Graph.Append_Label (2, Node_Label (+"LOL")); Copy_Graph.Append_Label (5, Node_Label (+"LOL")); Copy_Graph.Append_Label ((6, 5, 6), Edge_Label (+"KEK")); Copy_Graph.Append_Label ((7, 5, 7), Edge_Label (+"KEK")); Copy_Graph.Append_Label (10, Node_Label (+"KEK")); Copy_Graph.Append_Label ((4, 2, 4), Edge_Label (+"LOL")); if not Node_Perm (Graphs.Find_In_Subgraph (Position, Node_Label (+"LOL")), (1 => 5)) or not Edge_Perm (Graphs.Find_In_Subgraph (Position, Edge_Label (+"KEK")), ((6, 5, 6), (7, 5, 7))) then return Fail; end if; return Pass; end Find_Subgraph_Check; function Contains_Check return Test_Result is Copy_Graph : Graphs.Graph := My_Nonempty_Graph; begin if Copy_Graph.Contains (Node_ID (20)) or not Copy_Graph.Contains (Node_ID (2)) or Copy_Graph.Contains (Edge_ID (20)) or not Copy_Graph.Contains (Edge_ID (7)) or Copy_Graph.Contains (Graphs.Edge_Type'(99, 99, 99)) or not Copy_Graph.Contains (Graphs.Edge_Type'(7, 2, 5)) or Copy_Graph.Contains (Graphs.Labeled_Node_Type'(2, Node_Label (+"ABC"))) or Copy_Graph.Contains (Graphs.Labeled_Edge_Type'((7, 2, 5), Edge_Label (+"DEF"))) then return Fail; end if; Copy_Graph.Append_Label (2, Node_Label (+"ABC")); Copy_Graph.Append_Label ((7, 2, 5), Edge_Label (+"DEF")); if not Copy_Graph.Contains (Graphs.Labeled_Node_Type'(2, Node_Label (+"ABC"))) or not Copy_Graph.Contains (Graphs.Labeled_Edge_Type'((7, 2, 5), Edge_Label (+"DEF"))) then return Fail; end if; return Pass; end Contains_Check; function Contains_Label_Check return Test_Result is Copy_Graph : Graphs.Graph := My_Nonempty_Graph; begin if Copy_Graph.Contains_Label (Node_Label (+"ABC")) or Copy_Graph.Contains_Label (Edge_Label (+"DEF")) then return Fail; end if; Copy_Graph.Append_Label (2, Node_Label (+"ABC")); Copy_Graph.Append_Label ((7, 2, 5), Edge_Label (+"DEF")); if not Copy_Graph.Contains_Label (Node_Label (+"ABC")) or not Copy_Graph.Contains_Label (Edge_Label (+"DEF")) then return Fail; end if; return Pass; end Contains_Label_Check; function Contains_Subgraph_Check return Test_Result is Copy_Graph : Graphs.Graph := My_Complex_Graph; Branch_1 : Graphs.Cursor := Copy_Graph.To_Cursor (5); Branch_2 : Graphs.Cursor := Copy_Graph.To_Cursor (2); begin if Graphs.Contains_In_Subgraph (Branch_1, Node_ID (2)) or not Graphs.Contains_In_Subgraph (Branch_1, Node_ID (10)) or Graphs.Contains_In_Subgraph (Branch_1, Graphs.Edge_Type'(2, 2, 3)) or not Graphs.Contains_In_Subgraph (Branch_1, Graphs.Edge_Type'(13, 7, 5)) or Graphs.Contains_In_Subgraph (Branch_2, Node_ID (99)) or Graphs.Contains_In_Subgraph (Branch_2, Graphs.Edge_Type'(1, 99, 99)) or Graphs.Contains_In_Subgraph (Branch_1, Graphs.Labeled_Node_Type'(Node_ID (5), Node_Label (+"ABC"))) or Graphs.Contains_In_Subgraph (Branch_1, Graphs.Labeled_Edge_Type'((13, 7, 5), Edge_Label (+"DEF"))) then return Fail; end if; Copy_Graph.Append_Label (5, Node_Label (+"ABC")); Copy_Graph.Append_Label ((13, 7, 5), Edge_Label (+"DEF")); if Graphs.Contains_In_Subgraph (Branch_2, Graphs.Labeled_Node_Type'(Node_ID (5), Node_Label (+"ABC"))) or not Graphs.Contains_In_Subgraph (Branch_1, Graphs.Labeled_Node_Type'(Node_ID (5), Node_Label (+"ABC"))) or Graphs.Contains_In_Subgraph (Branch_2, Graphs.Labeled_Edge_Type'((13, 7, 5), Edge_Label (+"DEF"))) or not Graphs.Contains_In_Subgraph (Branch_1, Graphs.Labeled_Edge_Type'((13, 7, 5), Edge_Label (+"DEF"))) then return Fail; end if; return Pass; end Contains_Subgraph_Check; function Contains_Label_Subgraph_Check return Test_Result is Copy_Graph : Graphs.Graph := My_Complex_Graph; Branch_1 : Graphs.Cursor := Copy_Graph.To_Cursor (5); Branch_2 : Graphs.Cursor := Copy_Graph.To_Cursor (2); begin if Graphs.Contains_Label_In_Subgraph (Branch_1, Node_Label (+"ABC")) or Graphs.Contains_Label_In_Subgraph (Branch_1, Edge_Label (+"DEF")) or Graphs.Contains_Label_In_Subgraph (Branch_2, Node_Label (+"ABC")) or Graphs.Contains_Label_In_Subgraph (Branch_2, Edge_Label (+"DEF")) then return Fail; end if; Copy_Graph.Append_Label (5, Node_Label (+"ABC")); Copy_Graph.Append_Label ((8, 6, 8), Edge_Label (+"DEF")); if not Graphs.Contains_Label_In_Subgraph (Branch_1, Node_Label (+"ABC")) or not Graphs.Contains_Label_In_Subgraph (Branch_1, Edge_Label (+"DEF")) or Graphs.Contains_Label_In_Subgraph (Branch_2, Node_Label (+"ABC")) or Graphs.Contains_Label_In_Subgraph (Branch_2, Edge_Label (+"DEF")) then return Fail; end if; return Pass; end Contains_Label_Subgraph_Check; function Contains_Path_Check return Test_Result is Node_Path_In : Graphs.Node_Path := (1, 2, 3); Node_Path_Out : Graphs.Node_Path := (87, 88, 89, 100); Edge_Path_In : Graphs.Edge_Path := ((5, 1, 5), (6, 5, 6), (8, 6, 8)); Edge_Path_Out : Graphs.Edge_Path := ((1, 1, 4), (5, 4, 7)); begin if not My_Complex_Graph.Contains_Path (Node_Path_In) or My_Complex_Graph.Contains_Path (Node_Path_Out) or not My_Complex_Graph.Contains_Path (Edge_Path_In) or My_Complex_Graph.Contains_Path (Edge_Path_Out) then return Fail; end if; return Pass; end Contains_Path_Check; function Contains_Path_Subgraph_Check return Test_Result is Node_Path_In : Graphs.Node_Path := (5, 7, 7, 5); Node_Path_Out : Graphs.Node_Path := (1, 2, 3); Edge_Path_In : Graphs.Edge_Path := ((6, 5, 6), (8, 6, 8)); Edge_Path_Out : Graphs.Edge_Path := ((1, 1, 2), (2, 2, 3)); Position : Graphs.Cursor := My_Complex_Graph.To_Cursor (5); begin if not Graphs.Contains_Path_In_Subgraph (Position, Node_Path_In) or Graphs.Contains_Path_In_Subgraph (Position, Node_Path_Out) or not Graphs.Contains_Path_In_Subgraph (Position, Edge_Path_In) or Graphs.Contains_Path_In_Subgraph (Position, Edge_Path_Out) then return Fail; end if; return Pass; end Contains_Path_Subgraph_Check; function Iterate_Check return Test_Result is Index : Positive := 1; Check_1 : Graphs.Node_Array := (2, 5, 9, 11); Check_2 : Graphs.Node_Array := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); begin for C in My_Nonempty_Graph.Iterate loop if Index not in Check_1'Range or else Graphs.Element (C) /= Check_1 (Index) then return Fail; else Index := Index + 1; end if; end loop; Index := 1; for C in My_Complex_Graph.Iterate loop if Index not in Check_2'Range or else Graphs.Element (C) /= Check_2 (Index) then return Fail; else Index := Index + 1; end if; end loop; return Pass; end Iterate_Check; function Iterate_Subgraph_Check return Test_Result is Index : Positive := 1; Check : Graphs.Node_Array := (5, 6, 7, 8, 9, 10); Position_1 : Graphs.Cursor := My_Complex_Graph.To_Cursor (5); Position_2 : Graphs.Cursor := My_Complex_Graph.To_Cursor (7); begin for C in My_Complex_Graph.Iterate_Subgraph (Position_1) loop if Index not in Check'Range or else Graphs.Element (C) /= Check (Index) then return Fail; else Index := Index + 1; end if; end loop; Index := 1; for C in My_Complex_Graph.Iterate_Subgraph (Position_2) loop if Index not in Check'Range or else Graphs.Element (C) /= Check (Index) then return Fail; else Index := Index + 1; end if; end loop; return Pass; end Iterate_Subgraph_Check; function Iterate_By_Check return Test_Result is function Max (Nodes : in Graphs.Node_Array) return Node_ID is Current : Node_ID := 1; begin for N of Nodes loop if N > Current then Current := N; end if; end loop; return Current; end Max; function My_Choices (Position : in Graphs.Cursor) return Graphs.Cursor is Pick_From : Graphs.Node_Array := Graphs.Children (Position); begin if Pick_From'Length = 0 then return Graphs.No_Element; end if; return Graphs.Cursor_To (Position, Max (Pick_From)); end My_Choices; function My_Filter (Position : in Graphs.Cursor) return Boolean is begin return not Graphs.Has_Element (Position) or else Graphs.Element (Position) mod 2 = 0; end My_Filter; Index : Positive := 1; Check_1 : Graphs.Node_Array := (1, 5, 7, 10); Check_2 : Graphs.Node_Array := (1 => 10); Start : Graphs.Cursor := My_Complex_Graph.To_Cursor (1); begin for C in My_Complex_Graph.Iterate_By (Start, My_Choices'Unrestricted_Access) loop if Index not in Check_1'Range or else Graphs.Element (C) /= Check_1 (Index) then return Fail; else Index := Index + 1; end if; end loop; Index := 1; for C in My_Complex_Graph.Iterate_By (Start, My_Choices'Unrestricted_Access, My_Filter'Unrestricted_Access) loop if Index not in Check_2'Range or else Graphs.Element (C) /= Check_2 (Index) then return Fail; else Index := Index + 1; end if; end loop; return Pass; end Iterate_By_Check; end Graph_Tests.Search;