summaryrefslogtreecommitdiff
path: root/test/ratnest-tests-graphs.adb
blob: 24b03c90583781bb3313b34c821adc4623543e53 (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


separate (Ratnest.Tests)
package body Graphs is


    type My_Labels is (One, Two, Three, Four, Five, Six);

    package My_Graphs is new Packrat.Graphs (My_Labels, Character, String);


    use type My_Graphs.Node;
    use type My_Graphs.Cursor;
    use type My_Graphs.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  My_Graphs.Elements (Leafeon) /= "abc" or My_Graphs.Label (Brancheon) /= One or
            My_Graphs.Start (Leafeon) /= 1 or My_Graphs.Start (Brancheon) /= 4 or
            My_Graphs.Finish (Leafeon) /= 3 or My_Graphs.Finish (Brancheon) /= 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.Is_Nothing (My_Graphs.No_Position)
        then
            return Fail;
        end if;
        return Pass;
    end Empty_Check;


    function Attachment_Check
        return Test_Result
    is
        Leaf1 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
        Leaf2 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 4, 6));
        Leaf3 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 4, 6));
        Leaf4 : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("def", 1, 3));

        Brancheon : My_Graphs.Graph :=
            My_Graphs.Singleton (My_Graphs.Branch (Three, 1, 15));

        Merge1 : My_Graphs.Graph := Leaf1;
        Merge2 : My_Graphs.Graph := Leaf3;
        Merge3 : My_Graphs.Graph := Brancheon;

        Cursor1 : My_Graphs.Cursor := 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 My_Graphs.Is_Leaf (Merge1.Root (1)) or else
            not My_Graphs.Is_Leaf (Merge1.Root (2)) or else
            My_Graphs.Elements (Merge1.Root (1)) /= "abc" or else
            My_Graphs.Elements (Merge1.Root (2)) /= "def" or else
            not My_Graphs.Is_Leaf (Merge2.Root (1)) or else
            not My_Graphs.Is_Leaf (Merge2.Root (2)) or else
            My_Graphs.Elements (Merge2.Root (1)) /= "def" or else
            My_Graphs.Elements (Merge2.Root (2)) /= "abc" or else
            not My_Graphs.Is_Branch (Merge3.Root (1)) or else
            My_Graphs.Label (Cursor1) /= Three or else
            My_Graphs.Child_Count (Cursor1) /= 2 or else
            My_Graphs.Elements (My_Graphs.First_Child (Cursor1)) /= "abc" or else
            My_Graphs.Elements (My_Graphs.Last_Child (Cursor1)) /= "def"
        then
            return Fail;
        end if;
        return Pass;
    end Attachment_Check;


    function Find_Check
        return Test_Result
    is
        Leafeon   : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
        Brancheon : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 5));
        Combined  : My_Graphs.Graph := Brancheon;
    begin
        Combined.Attach_Choice (Combined.Root (1), Leafeon);
        declare
            Expected_Result : My_Graphs.Cursor := My_Graphs.First_Child (Combined.Root (1));
        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.Graph := My_Graphs.Singleton (My_Graphs.Leaf ("abc", 1, 3));
        Branch1  : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (One, 1, 4));
        Branch2  : My_Graphs.Graph := My_Graphs.Singleton (My_Graphs.Branch (Two, 1, 5));
        Combined : My_Graphs.Graph := Branch2;

        My_Cursor : My_Graphs.Cursor := Combined.Root (1);
    begin
        Combined.Attach_Choice (My_Cursor, Branch1);
        My_Cursor := My_Graphs.First_Child (My_Cursor);
        Combined.Attach_Choice (My_Cursor, Leafeon);

        declare
            Expected_Result : My_Graphs.Cursor := My_Graphs.First_Child (My_Cursor);
        begin
            if  My_Graphs.Find_In_Subgraph (My_Cursor, "abc") /= Expected_Result or
                My_Graphs.Find_In_Subgraph (My_Cursor, "def") /= My_Graphs.No_Position
            then
                return Fail;
            end if;
        end;
        return Pass;
    end Find_Subgraph_Check;


end Graphs;