Test-edges.C 3.98 KB
Newer Older
shunbo's avatar
shunbo committed
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
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | www.openfoam.com
     \\/     M anipulation  |
-------------------------------------------------------------------------------
    Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    Test-edges

Description
    Simple tests for edges

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "edgeList.H"
#include "edgeHashes.H"

using namespace Foam;

void printInfo(const edge& e)
{
    Info<< "edge: " << e << " count:" << e.count() << nl;
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//  Main program:

int main(int argc, char *argv[])
{
    edge e1;
    printInfo(e1);
    Info<<"has '2'? " << e1.found(2) << endl;

    edge e2(1, 2);
    printInfo(e2);
    Info<<"has '2'? " << e2.found(2) << endl;

    edge e3{2, 3};
    printInfo(e3);
    Info<<"has '2'? " << e3.found(2) << endl;

    edge e4(4, 4);
    printInfo(e4);
    Info<<"has '2'? " << e4.found(2) << endl;

    Info<<"collapse? -> " << e4.collapse() << endl;
    printInfo(e4);

    Info<< e3 << " connects " << e2 << " => " << e2.connects(e3) << endl;

    labelPair labels(e3);

    Info<< "as labelPair: " << labels << endl;

    edge e5;
    // Good: this fails (explicit constructor):   printInfo(labels);
    // Good: this also fails (no assignment operator): e5 = labels;

    // OK: explicit
    edge e6(labels);

    Info<< nl << "hash-like functionality" << nl;

    // doesn't work e4 = -1;
    e4.start() = e4.end() = -1;

    printInfo(e4);
    for (label i : {2, -1, 2, 1, 4, 1, 2, 3})
    {
        bool ok = e4.insert(i);
        Info<< "insert(" << i << ") = " << ok << " resulting ";
        printInfo(e4);
    }

    e4.start() = e4.end() = -1;
    Info<< "insert from list\n";
    labelHashSet newIndices({2, -1, 2, 1, 4, 1, 2, 3});
    e4.insert(newIndices.toc());
    printInfo(e4);

    e4.start() = e4.end() = -1;
    Info<< "insert from list\n";
    e4.insert({0, 5, 2, -1, 2, 1, 4, 1, 2, 3});
    printInfo(e4);

    FixedList<label, 8> otherIndices{12, 2, -1, 1, 4, 1, 2, 3};
    e4.start() = e4.end() = -1;
    Info<< "insert from list: " << otherIndices << nl;
    e4.insert(otherIndices);
    printInfo(e4);

    e4.start() = e4.end();
    Info<< "erase from list: " << otherIndices << nl;
    Info<< "removed " << e4.erase(otherIndices) << " values" << nl;
    printInfo(e4);

    for (label i : {-1, 0, 1, 3})
    {
        bool ok = e4.erase(i);
        Info<< "erase(" << i << ") = " << ok << " resulting ";
        printInfo(e4);
    }

    for (label i : {-1, 0, 1, 3})
    {
        bool ok = e4.insert(i);
        Info<< "insert(" << i << ") = " << ok << " resulting ";
        printInfo(e4);
    }
    e4.flip();
    Info<< "flipped ";
    printInfo(e4);

    for (label i : {-1, 0, 1, 3})
    {
        bool ok = e4.erase(i);
        Info<< "erase(" << i << ") = " << ok << " resulting ";
        printInfo(e4);
    }

    e4.sort();
    Info<< "sorted ";
    printInfo(e4);

    return 0;
}


// ************************************************************************* //