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-inspection.adb | 198 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 test/graph_tests-inspection.adb (limited to 'test/graph_tests-inspection.adb') diff --git a/test/graph_tests-inspection.adb b/test/graph_tests-inspection.adb new file mode 100644 index 0000000..ac2cdb3 --- /dev/null +++ b/test/graph_tests-inspection.adb @@ -0,0 +1,198 @@ + + +-- with Ada.Text_IO; +-- use Ada.Text_IO; + + +with Ada.Containers; + + +package body Graph_Tests.Inspection is + + + function Node_Count_Check + return Test_Result + is + use type Ada.Containers.Count_Type; + begin + if Graphs.Empty_Graph.Node_Count /= 0 or + My_Empty_Graph.Node_Count /= 0 or + My_Nonempty_Graph.Node_Count /= Some_Nodes'Length or + My_Complex_Graph.Node_Count /= Complex_Nodes'Length + then + return Fail; + end if; + return Pass; + end Node_Count_Check; + + + function Node_Count_Subgraph_Check + return Test_Result + is + use type Ada.Containers.Count_Type; + Cursor_1 : Graphs.Cursor := My_Complex_Graph.To_Cursor (1); + Cursor_2 : Graphs.Cursor := My_Complex_Graph.To_Cursor (5); + Cursor_3 : Graphs.Cursor := My_Complex_Graph.To_Cursor (7); + Cursor_4 : Graphs.Cursor := My_Complex_Graph.To_Cursor (6); + begin + if Graphs.Node_Count_In_Subgraph (Cursor_1) /= Complex_Nodes'Length or + Graphs.Node_Count_In_Subgraph (Cursor_2) /= 6 or + Graphs.Node_Count_In_Subgraph (Cursor_3) /= 6 or + Graphs.Node_Count_In_Subgraph (Cursor_4) /= 3 + then + return Fail; + end if; + return Pass; + end Node_Count_Subgraph_Check; + + + function Edge_Count_Check + return Test_Result + is + use type Ada.Containers.Count_Type; + begin + if Graphs.Empty_Graph.Edge_Count /= 0 or + My_Empty_Graph.Edge_Count /= 0 or + My_Nonempty_Graph.Edge_Count /= Some_Edges'Length or + My_Complex_Graph.Edge_Count /= Complex_Edges'Length + then + return Fail; + end if; + return Pass; + end Edge_Count_Check; + + + function Edge_Count_Subgraph_Check + return Test_Result + is + use type Ada.Containers.Count_Type; + Cursor_1 : Graphs.Cursor := My_Complex_Graph.To_Cursor (1); + Cursor_2 : Graphs.Cursor := My_Complex_Graph.To_Cursor (5); + Cursor_3 : Graphs.Cursor := My_Complex_Graph.To_Cursor (6); + begin + if Graphs.Edge_Count_In_Subgraph (Cursor_1) /= Complex_Edges'Length or + Graphs.Edge_Count_In_Subgraph (Cursor_2) /= 8 or + Graphs.Edge_Count_In_Subgraph (Cursor_3) /= 2 + then + return Fail; + end if; + return Pass; + end Edge_Count_Subgraph_Check; + + + function Nodes_Check + return Test_Result + is + function Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array); + Node_List : Graphs.Node_Array := My_Complex_Graph.Nodes; + begin + if Perm (Node_List, Complex_Nodes) then + return Pass; + else + return Fail; + end if; + end Nodes_Check; + + + function Nodes_Subgraph_Check + return Test_Result + is + function Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array); + Node_List_1 : Graphs.Node_Array := + Graphs.Nodes_In_Subgraph (My_Complex_Graph.To_Cursor (6)); + Node_List_2 : Graphs.Node_Array := + Graphs.Nodes_In_Subgraph (My_Complex_Graph.To_Cursor (7)); + Node_List_3 : Graphs.Node_Array := + Graphs.Nodes_In_Subgraph (My_Complex_Graph.To_Cursor (1)); + begin + if Perm (Node_List_1, (6, 8, 9)) and + Perm (Node_List_2, (5, 6, 10, 8, 9, 7)) and + Perm (Node_List_3, Complex_Nodes) + then + return Pass; + else + return Fail; + end if; + end Nodes_Subgraph_Check; + + + function Edges_Check + return Test_Result + is + function Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array); + Edge_List : Graphs.Edge_Array := My_Complex_Graph.Edges; + begin + if Perm (Edge_List, Complex_Edges) then + return Pass; + else + return Fail; + end if; + end Edges_Check; + + + function Edges_Subgraph_Check + return Test_Result + is + function Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array); + Edge_List_1 : Graphs.Edge_Array := + Graphs.Edges_In_Subgraph (My_Complex_Graph.To_Cursor (6)); + Edge_List_2 : Graphs.Edge_Array := + Graphs.Edges_In_Subgraph (My_Complex_Graph.To_Cursor (7)); + Edge_List_3 : Graphs.Edge_Array := + Graphs.Edges_In_Subgraph (My_Complex_Graph.To_Cursor (1)); + begin + if Perm (Edge_List_1, ((8, 6, 8), (9, 6, 9))) and + Perm (Edge_List_2, ((10, 7, 9), (11, 7, 10), (12, 7, 7), + (13, 7, 5), (6, 5, 6), (7, 5, 7), (8, 6, 8), (9, 6, 9))) and + Perm (Edge_List_3, Complex_Edges) + then + return Pass; + else + return Fail; + end if; + end Edges_Subgraph_Check; + + + function Node_Range_Check + return Test_Result + is + Min, Max : Node_ID; + begin + My_Complex_Graph.Node_Range (Min, Max); + if Min /= 1 or Max /= 10 then + return Fail; + end if; + My_Nonempty_Graph.Node_Range (Min, Max); + if Min /= 2 or Max /= 11 then + return Fail; + end if; + return Pass; + end Node_Range_Check; + + + function Unused_Check + return Test_Result + is + use type Graphs.Node_Array; + begin + if My_Empty_Graph.Unused /= Node_ID (1) or + My_Nonempty_Graph.Unused /= Node_ID (1) or + My_Complex_Graph.Unused /= Node_ID (11) or + My_Empty_Graph.Unused /= Edge_ID (1) or + My_Nonempty_Graph.Unused /= Edge_ID (1) or + My_Complex_Graph.Unused /= Edge_ID (14) or + Graphs.Unused (My_Nonempty_Graph.To_Cursor (2)) /= Node_ID (1) or + Graphs.Unused (My_Complex_Graph.To_Cursor (3)) /= Node_ID (11) or + Graphs.Unused (My_Nonempty_Graph.To_Cursor (2)) /= Edge_ID (1) or + Graphs.Unused (My_Complex_Graph.To_Cursor (10)) /= Edge_ID (14) or + My_Nonempty_Graph.Unused (8) /= (1, 3, 4, 6, 7, 8, 10, 12) + then + return Fail; + end if; + return Pass; + end Unused_Check; + + +end Graph_Tests.Inspection; + + -- cgit