summaryrefslogtreecommitdiff
path: root/test/graph_tests-inspection.adb
blob: ac2cdb326de45c2d2c867f97dccb9a7cfd7dbe50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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;