summaryrefslogtreecommitdiff
path: root/test/graph_tests-search.adb
blob: 17c2cbb461e5f3e71e18d5c36a1da785b2486d27 (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235


package body Graph_Tests.Search is


    function Find_Check
        return Test_Result
    is
        function Node_Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array);
        function Edge_Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array);
        Copy_Graph : Graphs.Graph := My_Complex_Graph;
    begin
        if not Node_Perm (Copy_Graph.Find (Node_Label (+"LOL")), No_Nodes) or
            not Edge_Perm (Copy_Graph.Find (Edge_Label (+"KEK")), No_Edges)
        then
            return Fail;
        end if;
        Copy_Graph.Append_Label (2, Node_Label (+"LOL"));
        Copy_Graph.Append_Label (5, Node_Label (+"LOL"));
        Copy_Graph.Append_Label ((6, 5, 6), Edge_Label (+"KEK"));
        Copy_Graph.Append_Label ((7, 5, 7), Edge_Label (+"KEK"));
        Copy_Graph.Append_Label (10, Node_Label (+"KEK"));
        Copy_Graph.Append_Label ((4, 2, 4), Edge_Label (+"LOL"));
        if not Node_Perm (Copy_Graph.Find (Node_Label (+"LOL")), (2, 5)) or
            not Edge_Perm (Copy_Graph.Find (Edge_Label (+"KEK")), ((6, 5, 6), (7, 5, 7)))
        then
            return Fail;
        end if;
        return Pass;
    end Find_Check;


    function Find_Subgraph_Check
        return Test_Result
    is
        function Node_Perm is new Is_Permutation (Node_ID, Positive, Graphs.Node_Array);
        function Edge_Perm is new Is_Permutation (Graphs.Edge_Type, Positive, Graphs.Edge_Array);
        Copy_Graph : Graphs.Graph := My_Complex_Graph;
        Position : Graphs.Cursor := Copy_Graph.To_Cursor (7);
    begin
        if not Node_Perm (Graphs.Find_In_Subgraph (Position, Node_Label (+"LOL")), No_Nodes) or
            not Edge_Perm (Graphs.Find_In_Subgraph (Position, Edge_Label (+"KEK")), No_Edges)
        then
            return Fail;
        end if;
        Copy_Graph.Append_Label (2, Node_Label (+"LOL"));
        Copy_Graph.Append_Label (5, Node_Label (+"LOL"));
        Copy_Graph.Append_Label ((6, 5, 6), Edge_Label (+"KEK"));
        Copy_Graph.Append_Label ((7, 5, 7), Edge_Label (+"KEK"));
        Copy_Graph.Append_Label (10, Node_Label (+"KEK"));
        Copy_Graph.Append_Label ((4, 2, 4), Edge_Label (+"LOL"));
        if not Node_Perm (Graphs.Find_In_Subgraph (Position, Node_Label (+"LOL")), (1 => 5)) or
            not Edge_Perm (Graphs.Find_In_Subgraph (Position, Edge_Label (+"KEK")),
                ((6, 5, 6), (7, 5, 7)))
        then
            return Fail;
        end if;
        return Pass;
    end Find_Subgraph_Check;


    function Contains_Check
        return Test_Result
    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
            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"))
        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"))
        then
            return Fail;
        end if;
        return Pass;
    end Contains_Check;


    function Contains_Label_Check
        return Test_Result
    is
        Copy_Graph : Graphs.Graph := My_Nonempty_Graph;
    begin
        if Copy_Graph.Contains_Label (Node_Label (+"ABC")) or
            Copy_Graph.Contains_Label (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_Label (Node_Label (+"ABC")) or
            not Copy_Graph.Contains_Label (Edge_Label (+"DEF"))
        then
            return Fail;
        end if;
        return Pass;
    end Contains_Label_Check;


    function Contains_Subgraph_Check
        return Test_Result
    is
        Copy_Graph : Graphs.Graph := My_Complex_Graph;
        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
            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_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"))
        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"))
        then
            return Fail;
        end if;
        return Pass;
    end Contains_Subgraph_Check;


    function Contains_Label_Subgraph_Check
        return Test_Result
    is
        Copy_Graph : Graphs.Graph := My_Complex_Graph;
        Branch_1 : Graphs.Cursor := Copy_Graph.To_Cursor (5);
        Branch_2 : Graphs.Cursor := Copy_Graph.To_Cursor (2);
    begin
        if Graphs.Contains_Label_In_Subgraph (Branch_1, Node_Label (+"ABC")) or
            Graphs.Contains_Label_In_Subgraph (Branch_1, Edge_Label (+"DEF")) or
            Graphs.Contains_Label_In_Subgraph (Branch_2, Node_Label (+"ABC")) or
            Graphs.Contains_Label_In_Subgraph (Branch_2, Edge_Label (+"DEF"))
        then
            return Fail;
        end if;
        Copy_Graph.Append_Label (5, Node_Label (+"ABC"));
        Copy_Graph.Append_Label ((8, 6, 8), Edge_Label (+"DEF"));
        if not Graphs.Contains_Label_In_Subgraph (Branch_1, Node_Label (+"ABC")) or
            not Graphs.Contains_Label_In_Subgraph (Branch_1, Edge_Label (+"DEF")) or
            Graphs.Contains_Label_In_Subgraph (Branch_2, Node_Label (+"ABC")) or
            Graphs.Contains_Label_In_Subgraph (Branch_2, Edge_Label (+"DEF"))
        then
            return Fail;
        end if;
        return Pass;
    end Contains_Label_Subgraph_Check;


    function Iterate_Check
        return Test_Result
    is
        Index : Positive := 1;
        Check_1 : Graphs.Node_Array := (2, 5, 9, 11);
        Check_2 : Graphs.Node_Array := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    begin
        for C in My_Nonempty_Graph.Iterate loop
            if Index not in Check_1'Range or else
                Graphs.Element (C) /= Check_1 (Index)
            then
                return Fail;
            else
                Index := Index + 1;
            end if;
        end loop;
        Index := 1;
        for C in My_Complex_Graph.Iterate loop
            if Index not in Check_2'Range or else
                Graphs.Element (C) /= Check_2 (Index)
            then
                return Fail;
            else
                Index := Index + 1;
            end if;
        end loop;
        return Pass;
    end Iterate_Check;


    function Iterate_Subgraph_Check
        return Test_Result
    is
        Index : Positive := 1;
        Check : Graphs.Node_Array := (5, 6, 7, 8, 9, 10);
        Position_1 : Graphs.Cursor := My_Complex_Graph.To_Cursor (5);
        Position_2 : Graphs.Cursor := My_Complex_Graph.To_Cursor (7);
    begin
        for C in My_Complex_Graph.Iterate_Subgraph (Position_1) loop
            if Index not in Check'Range or else
                Graphs.Element (C) /= Check (Index)
            then
                return Fail;
            else
                Index := Index + 1;
            end if;
        end loop;
        Index := 1;
        for C in My_Complex_Graph.Iterate_Subgraph (Position_2) loop
            if Index not in Check'Range or else
                Graphs.Element (C) /= Check (Index)
            then
                return Fail;
            else
                Index := Index + 1;
            end if;
        end loop;
        return Pass;
    end Iterate_Subgraph_Check;


end Graph_Tests.Search;