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 (C) 2018-2023 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
31{
32};
33
37BOOST_FIXTURE_TEST_SUITE( Distribute, DistributeFixture )
38
40{
41 std::vector<std::pair<int, int>> m_extents;
42 std::vector<int> m_expectedDeltas;
43};
44
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
62BOOST_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
75}
76
77BOOST_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
90}
91
92BOOST_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
112{
113 std::vector<int> m_points;
114 std::vector<int> m_expectedDeltas;
115};
116
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
134BOOST_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
143}
144
145BOOST_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
154}
155
156BOOST_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
167}
168
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
std::vector< int > GetDeltasForDistributeByPoints(const std::vector< int > &aItemPositions)
Definition: distribute.cpp:67
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()