summaryrefslogtreecommitdiff
path: root/test/graph_tests-modify.adb
blob: 0c1d5d96cfe31f6be20439f1d09b3998a81c53e3 (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


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;