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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
22#include <geometry/distribute.h>
23
24#include "geom_test_utils.h"
25
27{
28};
29
33BOOST_FIXTURE_TEST_SUITE( Distribute, DistributeFixture )
34
36{
37 std::vector<std::pair<int, int>> m_extents;
38 std::vector<int> m_expectedDeltas;
39};
40
42{
43 // Actally do the chamfer
44 const std::vector<int> deltas = GetDeltasForDistributeByGaps( aTestCase.m_extents );
45
46 BOOST_REQUIRE_EQUAL( deltas.size(), aTestCase.m_expectedDeltas.size() );
47
48 // First and last items should not be moved
49 BOOST_CHECK_EQUAL( deltas.front(), 0 );
50 BOOST_CHECK_EQUAL( deltas.back(), 0 );
51
52 for( size_t i = 0; i < deltas.size(); ++i )
53 {
54 BOOST_CHECK_EQUAL( deltas[i], aTestCase.m_expectedDeltas[i] );
55 }
56}
57
58BOOST_AUTO_TEST_CASE( DistributeGapsNoChangeNeeded )
59{
60 const DISTRIBUTE_GAPS_TEST_CASE testcase{
61 {
62 // Already evenly spaced (100 gaps)
63 { 0, 100 },
64 { 200, 300 },
65 { 400, 500 },
66 },
67 { 0, 0, 0 },
68 };
69
71}
72
73BOOST_AUTO_TEST_CASE( DistributeGapsSimpleShiftNeeded )
74{
75 const DISTRIBUTE_GAPS_TEST_CASE testcase{
76 {
77 // Need to move item 1 51 to the right
78 { 0, 100 },
79 { 149, 249 },
80 { 400, 500 },
81 },
82 { 0, 51, 0 },
83 };
84
86}
87
88BOOST_AUTO_TEST_CASE( DistributeGapsRounding )
89{
90 const DISTRIBUTE_GAPS_TEST_CASE testcase{
91 {
92 // Have to fit 3 gaps into total sum of gaps of 100
93 // so 33.333333 per gap
94 // (note one rounds up, the other down)
95 { -100, 0 },
96 { 0, 100 }, // Move this to 33 .. 133
97 { 0, 100 }, // Move this to 167 .. 267
98 { 300, 400 },
99 },
100 { 0, 33, 167, 0 },
101 };
102
103 DoDistributeGapsTestChecks( testcase );
104}
105
106
108{
109 std::vector<int> m_points;
110 std::vector<int> m_expectedDeltas;
111};
112
114{
115 // Actally do the chamfer
116 const std::vector<int> deltas = GetDeltasForDistributeByPoints( aTestCase.m_points );
117
118 BOOST_REQUIRE_EQUAL( deltas.size(), aTestCase.m_expectedDeltas.size() );
119
120 // First and last items should not be moved
121 BOOST_CHECK_EQUAL( deltas.front(), 0 );
122 BOOST_CHECK_EQUAL( deltas.back(), 0 );
123
124 for( size_t i = 0; i < deltas.size(); ++i )
125 {
126 BOOST_CHECK_EQUAL( deltas[i], aTestCase.m_expectedDeltas[i] );
127 }
128}
129
130BOOST_AUTO_TEST_CASE( DistributePointsNoChangeNeeded )
131{
132 const DISTRIBUTE_POINTS_TEST_CASE testcase{
133 // Already evenly spaced (100 gaps)
134 { 0, 100, 200, 300, 400 },
135 { 0, 0, 0, 0, 0 },
136 };
137
139}
140
141BOOST_AUTO_TEST_CASE( DistributePointsSimpleShiftNeeded )
142{
143 const DISTRIBUTE_POINTS_TEST_CASE testcase{
144 // Need to move item 1 51 to the right
145 { 0, 49, 200 },
146 { 0, 51, 0 },
147 };
148
150}
151
152BOOST_AUTO_TEST_CASE( DistributePointsRounding )
153{
154 const DISTRIBUTE_POINTS_TEST_CASE testcase{
155 // Have to fit 3 gaps into total sum of gaps of 100
156 // so 33.333333 per gap
157 // (note one rounds up, the other down)
158 { 0, 0, 0, 100 },
159 { 0, 33, 67, 0 },
160 };
161
163}
164
std::vector< int > GetDeltasForDistributeByGaps(const std::vector< std::pair< int, int > > &aItemExtents)
Given a list of 'n' item spans (e.g.
std::vector< int > GetDeltasForDistributeByPoints(const std::vector< int > &aItemPositions)
Declares the FilletFixture struct as the boost test fixture.
std::vector< std::pair< int, int > > m_extents
std::vector< int > m_expectedDeltas
std::vector< int > m_expectedDeltas
static void DoDistributeGapsTestChecks(const DISTRIBUTE_GAPS_TEST_CASE &aTestCase)
static void DoDistributePointsTestChecks(const DISTRIBUTE_POINTS_TEST_CASE &aTestCase)
BOOST_AUTO_TEST_CASE(DistributeGapsNoChangeNeeded)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")