separate (Ratnest.Tests) package body Graphs is type My_Labels is (One, Two, Three, Four, Five, Six); package My_Graphs is new Packrat.Graphs (My_Labels, Character, String); use type My_Graphs.Node; use type My_Graphs.Cursor; use type My_Graphs.Graph; function Node_Check return Test_Result is Leafeon : My_Graphs.Node := My_Graphs.Leaf ("abc", 1, 3); Brancheon : My_Graphs.Node := My_Graphs.Branch (One, 4, 3); begin if My_Graphs.Elements (Leafeon) /= "abc" or My_Graphs.Label (Brancheon) /= One or My_Graphs.Start (Leafeon) /= 1 or My_Graphs.Start (Brancheon) /= 4 or My_Graphs.Finish (Leafeon) /= 3 or My_Graphs.Finish (Brancheon) /= 3 then return Fail; end if; return Pass; end Node_Check; function Empty_Check return Test_Result is begin if not My_Graphs.Empty_Graph.Is_Empty or not My_Graphs.Is_Nothing (My_Graphs.No_Position) then return Fail; end if; return Pass; end Empty_Check; function Attachment_Check return Test_Result is Leaf1 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); Leaf2 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 4, 6)); Leaf3 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 4, 6)); Leaf4 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 1, 3)); Brancheon : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (Three, 1, 15)); Merge1 : My_Graphs.Graph := Leaf1; Merge2 : My_Graphs.Graph := Leaf3; Merge3 : My_Graphs.Graph := Brancheon; Cursor1 : My_Graphs.Cursor := Merge3.Root (1); begin Merge1.Append (Leaf2); Merge2.Prepend (Leaf4); Merge3.Attach_Choice (Cursor1, Merge1); if Merge1.Root_Count /= 2 or else Merge2.Root_Count /= 2 or else Merge3.Root_Count /= 1 or else not My_Graphs.Is_Leaf (Merge1.Root (1)) or else not My_Graphs.Is_Leaf (Merge1.Root (2)) or else My_Graphs.Elements (Merge1.Root (1)) /= "abc" or else My_Graphs.Elements (Merge1.Root (2)) /= "def" or else not My_Graphs.Is_Leaf (Merge2.Root (1)) or else not My_Graphs.Is_Leaf (Merge2.Root (2)) or else My_Graphs.Elements (Merge2.Root (1)) /= "def" or else My_Graphs.Elements (Merge2.Root (2)) /= "abc" or else not My_Graphs.Is_Branch (Merge3.Root (1)) or else My_Graphs.Label (Cursor1) /= Three or else My_Graphs.Child_Count (Cursor1) /= 2 or else My_Graphs.Elements (My_Graphs.First_Child (Cursor1)) /= "abc" or else My_Graphs.Elements (My_Graphs.Last_Child (Cursor1)) /= "def" then return Fail; end if; return Pass; end Attachment_Check; function Find_Check return Test_Result is Leafeon : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); Brancheon : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 5)); Combined : My_Graphs.Graph := Brancheon; begin Combined.Attach_Choice (Combined.Root (1), Leafeon); declare Expected_Result : My_Graphs.Cursor := My_Graphs.First_Child (Combined.Root (1)); begin if Combined.Find ("abc") /= Expected_Result or Combined.Find ("def") /= My_Graphs.No_Position or Brancheon.Find ("any") /= My_Graphs.No_Position then return Fail; end if; end; return Pass; end Find_Check; function Find_Subgraph_Check return Test_Result is Leafeon : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); Branch1 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 4)); Branch2 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (Two, 1, 5)); Combined : My_Graphs.Graph := Branch2; My_Cursor : My_Graphs.Cursor := Combined.Root (1); begin Combined.Attach_Choice (My_Cursor, Branch1); My_Cursor := My_Graphs.First_Child (My_Cursor); Combined.Attach_Choice (My_Cursor, Leafeon); declare Expected_Result : My_Graphs.Cursor := My_Graphs.First_Child (My_Cursor); begin if My_Graphs.Find_In_Subgraph (My_Cursor, "abc") /= Expected_Result or My_Graphs.Find_In_Subgraph (My_Cursor, "def") /= My_Graphs.No_Position then return Fail; end if; end; return Pass; end Find_Subgraph_Check; end Graphs;