From 56947ad5bbf0df7d35111010d0d5b7b3c19329cf Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Wed, 27 May 2020 17:51:42 +1000 Subject: Removed Follow, Path; Added LNode, LEdge, Node_Path, Edge_Path, Contains functions for Paths --- test/graph_tests-curses.adb | 13 ------- test/graph_tests-curses.ads | 2 -- test/graph_tests-modify.adb | 4 +-- test/graph_tests-search.adb | 83 +++++++++++++++++++++++++++++++++------------ test/graph_tests-search.ads | 4 +++ 5 files changed, 68 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/graph_tests-curses.adb b/test/graph_tests-curses.adb index 3667825..4d32ec1 100644 --- a/test/graph_tests-curses.adb +++ b/test/graph_tests-curses.adb @@ -59,19 +59,6 @@ package body Graph_Tests.Curses is end Previous_Check; - function Follow_Check - return Test_Result - is - use type Graphs.Cursor; - Start : Graphs.Cursor := My_Complex_Graph.To_Cursor (1); - begin - if Graphs.Follow (Start, (1, 1, 2)) /= My_Complex_Graph.To_Cursor (2) then - return Fail; - end if; - return Pass; - end Follow_Check; - - function Cursor_To_Check return Test_Result is diff --git a/test/graph_tests-curses.ads b/test/graph_tests-curses.ads index dff209b..302c7b3 100644 --- a/test/graph_tests-curses.ads +++ b/test/graph_tests-curses.ads @@ -11,7 +11,6 @@ package Graph_Tests.Curses is function Last_Check return Test_Result; function Next_Check return Test_Result; function Previous_Check return Test_Result; - function Follow_Check return Test_Result; function Cursor_To_Check return Test_Result; @@ -20,7 +19,6 @@ package Graph_Tests.Curses is (+"Last", Last_Check'Access), (+"Next", Next_Check'Access), (+"Previous", Previous_Check'Access), - (+"Follow", Follow_Check'Access), (+"Cursor_To", Cursor_To_Check'Access)); diff --git a/test/graph_tests-modify.adb b/test/graph_tests-modify.adb index 0c1d5d9..74f62a9 100644 --- a/test/graph_tests-modify.adb +++ b/test/graph_tests-modify.adb @@ -26,7 +26,7 @@ package body Graph_Tests.Modify is if Copy_Graph.To_Cursor (To_Insert) /= Graphs.No_Element then return Fail; end if; - Copy_Graph.Insert (To_Insert, Node_Label (+"HAHA")); + Copy_Graph.Insert (Graphs.Labeled_Node_Type'(To_Insert, Node_Label (+"HAHA"))); if Copy_Graph.To_Cursor (To_Insert) = Graphs.No_Element or else not Copy_Graph.Has_Label (To_Insert) or else Copy_Graph.Label (To_Insert) /= Node_Label (+"HAHA") @@ -60,7 +60,7 @@ package body Graph_Tests.Modify is return Fail; end if; To_Edge := Copy_Graph.Unused; - Copy_Graph.Insert ((To_Edge, 5, 11), Edge_Label (+"LOL")); + Copy_Graph.Insert (Graphs.Labeled_Edge_Type'((To_Edge, 5, 11), Edge_Label (+"LOL"))); if not Copy_Graph.Has_Edge (5, 11) or else not Copy_Graph.Has_Label ((To_Edge, 5, 11)) or else Copy_Graph.Label ((To_Edge, 5, 11)) /= Edge_Label (+"LOL") diff --git a/test/graph_tests-search.adb b/test/graph_tests-search.adb index d72ce67..9933c7d 100644 --- a/test/graph_tests-search.adb +++ b/test/graph_tests-search.adb @@ -64,23 +64,21 @@ package body Graph_Tests.Search is is Copy_Graph : Graphs.Graph := My_Nonempty_Graph; begin - if Copy_Graph.Contains (Graphs.No_Node) or - Copy_Graph.Contains (Graphs.No_Node, Node_Label (+"ABC")) or - Copy_Graph.Contains (Node_ID (20)) or + 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 ((99, 99, 99)) or - not Copy_Graph.Contains ((7, 2, 5)) or - Copy_Graph.Contains (2, Node_Label (+"ABC")) or - Copy_Graph.Contains ((7, 2, 5), Edge_Label (+"DEF")) + 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 (2, Node_Label (+"ABC")) or - not Copy_Graph.Contains ((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; @@ -116,25 +114,29 @@ package body Graph_Tests.Search is 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, Graphs.No_Node) or - Graphs.Contains_In_Subgraph (Branch_1, Graphs.No_Node, Node_Label (+"ABC")) or - Graphs.Contains_In_Subgraph (Branch_1, Node_ID (2)) or + 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, (2, 2, 3)) or - not Graphs.Contains_In_Subgraph (Branch_1, (13, 7, 5)) 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, (1, 99, 99)) or - Graphs.Contains_In_Subgraph (Branch_1, Node_ID (5), Node_Label (+"ABC")) or - Graphs.Contains_In_Subgraph (Branch_1, (13, 7, 5), Edge_Label (+"DEF")) + 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, Node_ID (5), Node_Label (+"ABC")) or - not Graphs.Contains_In_Subgraph (Branch_1, Node_ID (5), Node_Label (+"ABC")) or - Graphs.Contains_In_Subgraph (Branch_2, (13, 7, 5), Edge_Label (+"DEF")) or - not Graphs.Contains_In_Subgraph (Branch_1, (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; @@ -169,6 +171,45 @@ package body Graph_Tests.Search is 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 diff --git a/test/graph_tests-search.ads b/test/graph_tests-search.ads index 63602e7..f2c1740 100644 --- a/test/graph_tests-search.ads +++ b/test/graph_tests-search.ads @@ -13,6 +13,8 @@ package Graph_Tests.Search is function Contains_Label_Check return Test_Result; function Contains_Subgraph_Check return Test_Result; function Contains_Label_Subgraph_Check return Test_Result; + function Contains_Path_Check return Test_Result; + function Contains_Path_Subgraph_Check return Test_Result; function Iterate_Check return Test_Result; function Iterate_Subgraph_Check return Test_Result; function Iterate_By_Check return Test_Result; @@ -25,6 +27,8 @@ package Graph_Tests.Search is (+"Contains_Label", Contains_Label_Check'Access), (+"Contains_In_Subgraph", Contains_Subgraph_Check'Access), (+"Contains_Label_In_Subgraph", Contains_Label_Subgraph_Check'Access), + (+"Contains_Path", Contains_Path_Check'Access), + (+"Contains_Path_In_Subgraph", Contains_Path_Subgraph_Check'Access), (+"Iterate", Iterate_Check'Access), (+"Iterate_Subgraph", Iterate_Subgraph_Check'Access), (+"Iterate_By", Iterate_By_Check'Access)); -- cgit