From 82a42674ba64c6386152a5910fd7345a92b135e8 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 21 May 2020 21:24:25 +1000 Subject: Tests complete, minor bugs fixed --- test/graph_tests-modify.adb | 160 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 test/graph_tests-modify.adb (limited to 'test/graph_tests-modify.adb') diff --git a/test/graph_tests-modify.adb b/test/graph_tests-modify.adb new file mode 100644 index 0000000..0c1d5d9 --- /dev/null +++ b/test/graph_tests-modify.adb @@ -0,0 +1,160 @@ + + +with Ada.Containers; + + +package body Graph_Tests.Modify is + + + function Insert_Check + return Test_Result + is + use type Graphs.Cursor; + To_Insert : Node_ID; + To_Edge : Edge_ID; + Copy_Graph : Graphs.Graph := My_Nonempty_Graph; + begin + To_Insert := Copy_Graph.Unused; + if Copy_Graph.To_Cursor (To_Insert) /= Graphs.No_Element then + return Fail; + end if; + Copy_Graph.Insert (To_Insert); + if Copy_Graph.To_Cursor (To_Insert) = Graphs.No_Element then + return Fail; + end if; + To_Insert := Copy_Graph.Unused; + if Copy_Graph.To_Cursor (To_Insert) /= Graphs.No_Element then + return Fail; + end if; + Copy_Graph.Insert (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") + then + return Fail; + end if; + declare + Insert_Nodes : Graphs.Node_Array := Copy_Graph.Unused (5); + begin + for N of Insert_Nodes loop + if Copy_Graph.To_Cursor (N) /= Graphs.No_Element then + return Fail; + end if; + end loop; + Copy_Graph.Insert (Insert_Nodes); + for N of Insert_Nodes loop + if Copy_Graph.To_Cursor (N) = Graphs.No_Element then + return Fail; + end if; + end loop; + end; + if Copy_Graph.Has_Edge (5, 9) then + return Fail; + end if; + To_Edge := Copy_Graph.Unused; + Copy_Graph.Insert (Graphs.Edge_Type'(To_Edge, 5, 9)); + if not Copy_Graph.Has_Edge (5, 9) then + return Fail; + end if; + if Copy_Graph.Has_Edge (5, 11) then + return Fail; + end if; + To_Edge := Copy_Graph.Unused; + Copy_Graph.Insert ((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") + then + return Fail; + end if; + return Pass; + end Insert_Check; + + + function Delete_Check + return Test_Result + is + use type Graphs.Cursor; + use type Ada.Containers.Count_Type; + Copy_Graph : Graphs.Graph := My_Nonempty_Graph; + begin + if Copy_Graph.To_Cursor (2) = Graphs.No_Element then + return Fail; + end if; + Copy_Graph.Delete (2); + if Copy_Graph.To_Cursor (2) /= Graphs.No_Element or + Copy_Graph.Node_Count /= 3 or + Copy_Graph.Edge_Count /= 1 + then + return Fail; + end if; + if not Copy_Graph.Has_Edge (9, 11) then + return Fail; + end if; + Copy_Graph.Delete (Graphs.Edge_Type'(2, 9, 11)); + if Copy_Graph.Has_Edge (9, 11) or + Copy_Graph.Edge_Count /= 0 + then + return Fail; + end if; + return Pass; + end Delete_Check; + + + function Delete_Subgraph_Check + return Test_Result + is + use type Graphs.Cursor; + use type Ada.Containers.Count_Type; + Copy_Graph : Graphs.Graph := My_Complex_Graph; + Position : Graphs.Cursor := Copy_Graph.To_Cursor (2); + begin + Graphs.Delete_Subgraph (Position); + if Copy_Graph.To_Cursor (2) /= Graphs.No_Element or + Copy_Graph.Node_Count /= 7 or + Copy_Graph.Edge_Count /= 9 + then + return Fail; + end if; + return Pass; + end Delete_Subgraph_Check; + + + function Swap_Check + return Test_Result + is + use type Ada.Containers.Count_Type; + function Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array); + Copy_Graph : Graphs.Graph := My_Complex_Graph; + Left_Parents : Graphs.Node_Array := Copy_Graph.Parents (2); + Left_Children : Graphs.Node_Array := Copy_Graph.Children (2); + Left_Indegree : Ada.Containers.Count_Type := Copy_Graph.Indegree (2); + Left_Outdegree : Ada.Containers.Count_Type := Copy_Graph.Outdegree (2); + Right_Parents : Graphs.Node_Array := Copy_Graph.Parents (5); + Right_Children : Graphs.Node_Array := Copy_Graph.Children (5); + Right_Indegree : Ada.Containers.Count_Type := Copy_Graph.Indegree (5); + Right_Outdegree : Ada.Containers.Count_Type := Copy_Graph.Outdegree (5); + begin + Copy_Graph.Append_Label (2, Node_Label (+"ABC")); + Copy_Graph.Append_Label (5, Node_Label (+"DEF")); + Copy_Graph.Swap (2, 5); + if not Perm (Copy_Graph.Parents (2), Right_Parents) or + not Perm (Copy_Graph.Children (2), Right_Children) or + not Perm (Copy_Graph.Parents (5), Left_Parents) or + not Perm (Copy_Graph.Children (5), Left_Children) or + Copy_Graph.Label (2) /= Node_Label (+"ABC") or + Copy_Graph.Label (5) /= Node_Label (+"DEF") or + Copy_Graph.Indegree (2) /= Right_Indegree or + Copy_Graph.Outdegree (2) /= Right_Outdegree or + Copy_Graph.Indegree (5) /= Left_Indegree or + Copy_Graph.Outdegree (5) /= Left_Outdegree + then + return Fail; + end if; + return Pass; + end Swap_Check; + + +end Graph_Tests.Modify; + + -- cgit