File: point_list_test.cpp

package info (click to toggle)
sight 25.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,252 kB
  • sloc: cpp: 310,629; xml: 17,622; ansic: 9,960; python: 1,379; sh: 144; makefile: 33
file content (233 lines) | stat: -rw-r--r-- 7,157 bytes parent folder | download
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
/************************************************************************
 *
 * Copyright (C) 2009-2025 IRCAD France
 * Copyright (C) 2012-2021 IHU Strasbourg
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#include "point_list_test.hpp"

#include <data/point.hpp>
#include <data/point_list.hpp>

// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::data::ut::point_list_test);

namespace sight::data::ut
{

//------------------------------------------------------------------------------

void point_list_test::setUp()
{
    // Set up context before running a test.
}

//------------------------------------------------------------------------------

void point_list_test::tearDown()
{
    // Clean up after the test run.
}

//------------------------------------------------------------------------------

void point_list_test::copy_test()
{
    data::point_list::sptr pl1 = std::make_shared<data::point_list>();
    data::point_list::sptr pl2 = std::make_shared<data::point_list>();
    data::point_list::sptr pl3 = std::make_shared<data::point_list>();

    data::point::sptr point1 = std::make_shared<data::point>(1.0F, 2.0F, 3.0F);

    pl1->push_back(point1);

    CPPUNIT_ASSERT_NO_THROW(pl2->shallow_copy(pl1));

    CPPUNIT_ASSERT_EQUAL(pl1->get_points()[0], pl2->get_points()[0]);
}

//------------------------------------------------------------------------------

void point_list_test::getter_test()
{
    data::point_list::sptr pl1 = std::make_shared<data::point_list>();
    data::point::sptr point1   = std::make_shared<data::point>(1.0F, 2.0F, 3.0F);

    pl1->push_back(point1);

    data::point::sptr point2 = pl1->get_points()[0];

    CPPUNIT_ASSERT_EQUAL((*point1)[0], (*point2)[0]);
    CPPUNIT_ASSERT_EQUAL((*point1)[1], (*point2)[1]);
    CPPUNIT_ASSERT_EQUAL((*point1)[2], (*point2)[2]);

    data::point_list::container_t& container = pl1->get_points();

    CPPUNIT_ASSERT_EQUAL((*point1)[0], (*container[0])[0]);
    CPPUNIT_ASSERT_EQUAL((*point1)[1], (*container[0])[1]);
    CPPUNIT_ASSERT_EQUAL((*point1)[2], (*container[0])[2]);
}

//------------------------------------------------------------------------------

void point_list_test::setter_test()
{
    data::point_list::sptr pl1 = std::make_shared<data::point_list>();
    data::point::sptr point1   = std::make_shared<data::point>(1.0F, 2.0F, 3.0F);
    data::point::sptr point2   = std::make_shared<data::point>(4.0F, 5.0F, 6.0F);

    std::vector<data::point::sptr> vec;
    vec.push_back(point1);
    vec.push_back(point2);

    CPPUNIT_ASSERT_NO_THROW(pl1->set_points(vec));

    data::point_list::container_t& container = pl1->get_points();

    for(unsigned p = 0 ; p < vec.size() ; ++p)
    {
        for(unsigned int i = 0 ; i < 3 ; ++i)
        {
            CPPUNIT_ASSERT_EQUAL((*vec[p])[i], (*container[p])[i]);
        }
    }
}

//------------------------------------------------------------------------------

void point_list_test::push_test()
{
    data::point_list::sptr pl1 = std::make_shared<data::point_list>();
    data::point::sptr point1   = std::make_shared<data::point>(1.0F, 2.0F, 3.0F);
    data::point::sptr point2   = std::make_shared<data::point>(4.0F, 5.0F, 6.0F);

    std::vector<data::point::sptr> vec;
    vec.push_back(point1);
    vec.push_back(point2);

    CPPUNIT_ASSERT_NO_THROW(pl1->push_back(point1));
    CPPUNIT_ASSERT_NO_THROW(pl1->push_back(point2));

    data::point_list::container_t& container = pl1->get_points();

    for(unsigned p = 0 ; p < vec.size() ; ++p)
    {
        for(unsigned int i = 0 ; i < 3 ; ++i)
        {
            CPPUNIT_ASSERT_EQUAL((*vec[p])[i], (*container[p])[i]);
        }
    }
}

//------------------------------------------------------------------------------

void point_list_test::remove_test()
{
    const std::size_t nb_points = 42;
    data::point_list::sptr pl   = std::make_shared<data::point_list>();

    // Remove first
    {
        // Build a list
        for(std::size_t i = 0 ; i < nb_points ; ++i)
        {
            const auto p = std::make_shared<data::point>(.0F, .0F, .0F);
            pl->push_back(p);
        }

        // remove the first
        std::size_t size = nb_points;
        while(!pl->get_points().empty())
        {
            pl->remove(0);
            CPPUNIT_ASSERT_EQUAL(--size, pl->get_points().size());
        }
    }

    CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), pl->get_points().size());

    // Remove last
    {
        // Build a list
        for(std::size_t i = 0 ; i < nb_points ; ++i)
        {
            const auto p = std::make_shared<data::point>(.0F, .0F, .0F);
            pl->push_back(p);
        }

        // remove the last
        std::size_t size = nb_points;
        while(!pl->get_points().empty())
        {
            const std::size_t index = pl->get_points().size() - 1;
            pl->remove(index);
            CPPUNIT_ASSERT_EQUAL(--size, pl->get_points().size());
        }
    }

    CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), pl->get_points().size());

    // Check that the correct one is removed
    {
        // Build a list
        for(std::size_t i = 0 ; i < nb_points ; ++i)
        {
            const auto p = std::make_shared<data::point>(static_cast<float>(i), .0F, .0F);
            pl->push_back(p);
        }

        std::size_t size = nb_points;
        while(!pl->get_points().empty())
        {
            const std::size_t index = size / 2;
            const auto ref          = pl->get_points()[index];
            pl->remove(index);
            CPPUNIT_ASSERT_EQUAL(--size, pl->get_points().size());
            for(const auto& p : pl->get_points())
            {
                CPPUNIT_ASSERT((*ref)[0] != (*p)[0]);
            }
        }
    }
}

//------------------------------------------------------------------------------

void point_list_test::clear_test()
{
    const std::size_t nb_points = 42;
    data::point_list::sptr pl   = std::make_shared<data::point_list>();

    CPPUNIT_ASSERT(pl->get_points().empty());
    pl->clear();
    CPPUNIT_ASSERT(pl->get_points().empty());

    // Build a list
    for(std::size_t i = 0 ; i < nb_points ; i++)
    {
        const auto p = std::make_shared<data::point>(.0F, .0F, .0F);
        pl->push_back(p);
    }

    CPPUNIT_ASSERT(pl->get_points().size() == nb_points);
    pl->clear();
    CPPUNIT_ASSERT(pl->get_points().empty());
}

} // namespace sight::data::ut