diff options
Diffstat (limited to 'test/ratnest-tests-graphs.adb')
-rw-r--r-- | test/ratnest-tests-graphs.adb | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/test/ratnest-tests-graphs.adb b/test/ratnest-tests-graphs.adb new file mode 100644 index 0000000..8776336 --- /dev/null +++ b/test/ratnest-tests-graphs.adb @@ -0,0 +1,132 @@ + + +separate (Ratnest.Tests) +package body Graphs is + + + type My_Labels is (One, Two, Three, Four, Five, Six); + + package My_Interfaces is new Packrat.Interfaces (My_Labels, Character, String); + package My_Graphs is new Packrat.Graphs (My_Labels, Character, String, My_Interfaces); + + + use type My_Interfaces.Cursor; + use type My_Graphs.Parse_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 Leafeon.Elements /= "abc" or Brancheon.Label /= One or + Leafeon.Start /= 1 or Brancheon.Start /= 4 or + Leafeon.Finish /= 3 or Brancheon.Finish /= 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.No_Position.Is_Nothing then + return Fail; + end if; + return Pass; + end Empty_Check; + + + function Attachment_Check + return Test_Result + is + Leaf1 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); + Leaf2 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 4, 6)); + Leaf3 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 4, 6)); + Leaf4 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 1, 3)); + + Brancheon : My_Graphs.Parse_Graph := + My_Graphs.Singleton (My_Graphs.Branch (Three, 1, 15)); + + Merge1 : My_Graphs.Parse_Graph := Leaf1; + Merge2 : My_Graphs.Parse_Graph := Leaf3; + Merge3 : My_Graphs.Parse_Graph := Brancheon; + + Cursor1 : My_Interfaces.Cursor'Class := 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 Merge1.Root (1).Is_Leaf or else not Merge1.Root (2).Is_Leaf or else + Merge1.Root (1).Elements /= "abc" or else Merge1.Root (2).Elements /= "def" or else + not Merge2.Root (1).Is_Leaf or else not Merge2.Root (2).Is_Leaf or else + Merge2.Root (1).Elements /= "def" or else Merge2.Root (2).Elements /= "abc" or else + not Merge3.Root (1).Is_Branch or else + Cursor1.Label /= Three or else Cursor1.Child_Count /= 2 or else + Cursor1.First_Child.Elements /= "abc" or else Cursor1.Last_Child.Elements /= "def" + then + return Fail; + end if; + return Pass; + end Attachment_Check; + + + function Find_Check + return Test_Result + is + Leafeon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); + Brancheon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 5)); + Combined : My_Graphs.Parse_Graph := Brancheon; + begin + Combined.Attach_Choice (Combined.Root (1), Leafeon); + declare + Expected_Result : My_Interfaces.Cursor'Class := Combined.Root (1).First_Child; + 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.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3)); + Branch1 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 4)); + Branch2 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (Two, 1, 5)); + Combined : My_Graphs.Parse_Graph := Branch2; + + My_Cursor : My_Interfaces.Cursor'Class := Combined.Root (1); + begin + Combined.Attach_Choice (My_Cursor, Branch1); + My_Cursor := My_Cursor.First_Child; + Combined.Attach_Choice (My_Cursor, Leafeon); + + declare + Expected_Result : My_Interfaces.Cursor'Class := My_Cursor.First_Child; + begin + if My_Cursor.Find_In_Subgraph ("abc") /= Expected_Result or + My_Cursor.Find_In_Subgraph ("def") /= My_Graphs.No_Position + then + return Fail; + end if; + end; + return Pass; + end Find_Subgraph_Check; + + +end Graphs; + + |