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
|
separate (Ratnest.Tests)
package body Graphs is
type My_Labels is (One, Two, Three, Four, Five, Six);
package My_Interfaces is new Packrat.Interfaces (My_Labels, Character, String);
package My_Graphs is new Packrat.Graphs (My_Labels, Character, String, My_Interfaces);
use type My_Interfaces.Cursor;
use type My_Graphs.Parse_Graph;
function Node_Check
return Test_Result
is
Leafeon : My_Graphs.Node := My_Graphs.Leaf ("abc", 1, 3);
Brancheon : My_Graphs.Node := My_Graphs.Branch (One, 4, 3);
begin
if Leafeon.Elements /= "abc" or Brancheon.Label /= One or
Leafeon.Start /= 1 or Brancheon.Start /= 4 or
Leafeon.Finish /= 3 or Brancheon.Finish /= 3
then
return Fail;
end if;
return Pass;
end Node_Check;
function Empty_Check
return Test_Result is
begin
if not My_Graphs.Empty_Graph.Is_Empty or not My_Graphs.No_Position.Is_Nothing then
return Fail;
end if;
return Pass;
end Empty_Check;
function Attachment_Check
return Test_Result
is
Leaf1 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
Leaf2 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 4, 6));
Leaf3 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 4, 6));
Leaf4 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 1, 3));
Brancheon : My_Graphs.Parse_Graph :=
My_Graphs.Singleton (My_Graphs.Branch (Three, 1, 15));
Merge1 : My_Graphs.Parse_Graph := Leaf1;
Merge2 : My_Graphs.Parse_Graph := Leaf3;
Merge3 : My_Graphs.Parse_Graph := Brancheon;
Cursor1 : My_Interfaces.Cursor'Class := Merge3.Root (1);
begin
Merge1.Append (Leaf2);
Merge2.Prepend (Leaf4);
Merge3.Attach_Choice (Cursor1, Merge1);
if Merge1.Root_Count /= 2 or else
Merge2.Root_Count /= 2 or else
Merge3.Root_Count /= 1 or else
not Merge1.Root (1).Is_Leaf or else not Merge1.Root (2).Is_Leaf or else
Merge1.Root (1).Elements /= "abc" or else Merge1.Root (2).Elements /= "def" or else
not Merge2.Root (1).Is_Leaf or else not Merge2.Root (2).Is_Leaf or else
Merge2.Root (1).Elements /= "def" or else Merge2.Root (2).Elements /= "abc" or else
not Merge3.Root (1).Is_Branch or else
Cursor1.Label /= Three or else Cursor1.Child_Count /= 2 or else
Cursor1.First_Child.Elements /= "abc" or else Cursor1.Last_Child.Elements /= "def"
then
return Fail;
end if;
return Pass;
end Attachment_Check;
function Find_Check
return Test_Result
is
Leafeon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
Brancheon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 5));
Combined : My_Graphs.Parse_Graph := Brancheon;
begin
Combined.Attach_Choice (Combined.Root (1), Leafeon);
declare
Expected_Result : My_Interfaces.Cursor'Class := Combined.Root (1).First_Child;
begin
if Combined.Find ("abc") /= Expected_Result or
Combined.Find ("def") /= My_Graphs.No_Position or
Brancheon.Find ("any") /= My_Graphs.No_Position
then
return Fail;
end if;
end;
return Pass;
end Find_Check;
function Find_Subgraph_Check
return Test_Result
is
Leafeon : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
Branch1 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 4));
Branch2 : My_Graphs.Parse_Graph := My_Graphs.Singleton (My_Graphs.Branch (Two, 1, 5));
Combined : My_Graphs.Parse_Graph := Branch2;
My_Cursor : My_Interfaces.Cursor'Class := Combined.Root (1);
begin
Combined.Attach_Choice (My_Cursor, Branch1);
My_Cursor := My_Cursor.First_Child;
Combined.Attach_Choice (My_Cursor, Leafeon);
declare
Expected_Result : My_Interfaces.Cursor'Class := My_Cursor.First_Child;
begin
if My_Cursor.Find_In_Subgraph ("abc") /= Expected_Result or
My_Cursor.Find_In_Subgraph ("def") /= My_Graphs.No_Position
then
return Fail;
end if;
end;
return Pass;
end Find_Subgraph_Check;
end Graphs;
|