KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_distribute.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include <boost/test/unit_test.hpp>
25
26
#include <
geometry/distribute.h
>
27
28
#include "
geom_test_utils.h
"
29
30
struct
DistributeFixture
31
{
32
};
33
37
BOOST_FIXTURE_TEST_SUITE( Distribute,
DistributeFixture
)
38
39
struct
DISTRIBUTE_GAPS_TEST_CASE
40
{
41
std::vector<std::pair<int, int>>
m_extents
;
42
std::vector<int>
m_expectedDeltas
;
43
};
44
45
static
void
DoDistributeGapsTestChecks
(
const
DISTRIBUTE_GAPS_TEST_CASE
& aTestCase )
46
{
47
// Actally do the chamfer
48
const
std::vector<int> deltas =
GetDeltasForDistributeByGaps
( aTestCase.
m_extents
);
49
50
BOOST_REQUIRE_EQUAL( deltas.size(), aTestCase.
m_expectedDeltas
.size() );
51
52
// First and last items should not be moved
53
BOOST_CHECK_EQUAL
( deltas.front(), 0 );
54
BOOST_CHECK_EQUAL
( deltas.back(), 0 );
55
56
for
(
size_t
i = 0; i < deltas.size(); ++i )
57
{
58
BOOST_CHECK_EQUAL
( deltas[i], aTestCase.
m_expectedDeltas
[i] );
59
}
60
}
61
62
BOOST_AUTO_TEST_CASE
( DistributeGapsNoChangeNeeded )
63
{
64
const
DISTRIBUTE_GAPS_TEST_CASE
testcase{
65
{
66
// Already evenly spaced (100 gaps)
67
{ 0, 100 },
68
{ 200, 300 },
69
{ 400, 500 },
70
},
71
{ 0, 0, 0 },
72
};
73
74
DoDistributeGapsTestChecks
( testcase );
75
}
76
77
BOOST_AUTO_TEST_CASE
( DistributeGapsSimpleShiftNeeded )
78
{
79
const
DISTRIBUTE_GAPS_TEST_CASE
testcase{
80
{
81
// Need to move item 1 51 to the right
82
{ 0, 100 },
83
{ 149, 249 },
84
{ 400, 500 },
85
},
86
{ 0, 51, 0 },
87
};
88
89
DoDistributeGapsTestChecks
( testcase );
90
}
91
92
BOOST_AUTO_TEST_CASE
( DistributeGapsRounding )
93
{
94
const
DISTRIBUTE_GAPS_TEST_CASE
testcase{
95
{
96
// Have to fit 3 gaps into total sum of gaps of 100
97
// so 33.333333 per gap
98
// (note one rounds up, the other down)
99
{ -100, 0 },
100
{ 0, 100 },
// Move this to 33 .. 133
101
{ 0, 100 },
// Move this to 167 .. 267
102
{ 300, 400 },
103
},
104
{ 0, 33, 167, 0 },
105
};
106
107
DoDistributeGapsTestChecks
( testcase );
108
}
109
110
111
struct
DISTRIBUTE_POINTS_TEST_CASE
112
{
113
std::vector<int>
m_points
;
114
std::vector<int>
m_expectedDeltas
;
115
};
116
117
static
void
DoDistributePointsTestChecks
(
const
DISTRIBUTE_POINTS_TEST_CASE
& aTestCase )
118
{
119
// Actally do the chamfer
120
const
std::vector<int> deltas =
GetDeltasForDistributeByPoints
( aTestCase.
m_points
);
121
122
BOOST_REQUIRE_EQUAL( deltas.size(), aTestCase.
m_expectedDeltas
.size() );
123
124
// First and last items should not be moved
125
BOOST_CHECK_EQUAL
( deltas.front(), 0 );
126
BOOST_CHECK_EQUAL
( deltas.back(), 0 );
127
128
for
(
size_t
i = 0; i < deltas.size(); ++i )
129
{
130
BOOST_CHECK_EQUAL
( deltas[i], aTestCase.
m_expectedDeltas
[i] );
131
}
132
}
133
134
BOOST_AUTO_TEST_CASE
( DistributePointsNoChangeNeeded )
135
{
136
const
DISTRIBUTE_POINTS_TEST_CASE
testcase{
137
// Already evenly spaced (100 gaps)
138
{ 0, 100, 200, 300, 400 },
139
{ 0, 0, 0, 0, 0 },
140
};
141
142
DoDistributePointsTestChecks
( testcase );
143
}
144
145
BOOST_AUTO_TEST_CASE
( DistributePointsSimpleShiftNeeded )
146
{
147
const
DISTRIBUTE_POINTS_TEST_CASE
testcase{
148
// Need to move item 1 51 to the right
149
{ 0, 49, 200 },
150
{ 0, 51, 0 },
151
};
152
153
DoDistributePointsTestChecks
( testcase );
154
}
155
156
BOOST_AUTO_TEST_CASE
( DistributePointsRounding )
157
{
158
const
DISTRIBUTE_POINTS_TEST_CASE
testcase{
159
// Have to fit 3 gaps into total sum of gaps of 100
160
// so 33.333333 per gap
161
// (note one rounds up, the other down)
162
{ 0, 0, 0, 100 },
163
{ 0, 33, 67, 0 },
164
};
165
166
DoDistributePointsTestChecks
( testcase );
167
}
168
169
BOOST_AUTO_TEST_SUITE_END
()
distribute.h
GetDeltasForDistributeByGaps
std::vector< int > GetDeltasForDistributeByGaps(const std::vector< std::pair< int, int > > &aItemExtents)
Given a list of 'n' item spans (e.g.
Definition
distribute.cpp:25
GetDeltasForDistributeByPoints
std::vector< int > GetDeltasForDistributeByPoints(const std::vector< int > &aItemPositions)
Definition
distribute.cpp:67
geom_test_utils.h
DISTRIBUTE_GAPS_TEST_CASE
Declares the FilletFixture struct as the boost test fixture.
Definition
test_distribute.cpp:40
DISTRIBUTE_GAPS_TEST_CASE::m_extents
std::vector< std::pair< int, int > > m_extents
Definition
test_distribute.cpp:41
DISTRIBUTE_GAPS_TEST_CASE::m_expectedDeltas
std::vector< int > m_expectedDeltas
Definition
test_distribute.cpp:42
DISTRIBUTE_POINTS_TEST_CASE
Definition
test_distribute.cpp:112
DISTRIBUTE_POINTS_TEST_CASE::m_points
std::vector< int > m_points
Definition
test_distribute.cpp:113
DISTRIBUTE_POINTS_TEST_CASE::m_expectedDeltas
std::vector< int > m_expectedDeltas
Definition
test_distribute.cpp:114
DistributeFixture
Definition
test_distribute.cpp:31
DoDistributeGapsTestChecks
static void DoDistributeGapsTestChecks(const DISTRIBUTE_GAPS_TEST_CASE &aTestCase)
Definition
test_distribute.cpp:45
DoDistributePointsTestChecks
static void DoDistributePointsTestChecks(const DISTRIBUTE_POINTS_TEST_CASE &aTestCase)
Definition
test_distribute.cpp:117
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(DistributeGapsNoChangeNeeded)
Definition
test_distribute.cpp:62
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
src
qa
tests
libs
kimath
geometry
test_distribute.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2