KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_array_axis.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
28
30
31#include <array_axis.h>
32
36BOOST_AUTO_TEST_SUITE( ArrayAxis )
37
45
46
50BOOST_AUTO_TEST_CASE( ValidOffsets )
51{
52 // clang-format off
53 const std::vector<VALID_OFFSET_CASE> cases = {
54 {
56 "0",
57 true,
58 0,
59 },
60 {
62 "1",
63 true,
64 1,
65 },
66 {
68 "1234",
69 true,
70 1234,
71 },
72 {
74 "",
75 false,
76 0,
77 },
78 {
80 "www",
81 false,
82 0,
83 },
84 {
86 "A",
87 true,
88 0,
89 },
90 {
92 "XY",
93 true,
94 648,
95 },
96 {
98 "A0",
99 true,
100 160,
101 },
102 {
104 "G0",
105 false,
106 0,
107 },
108 // Lowercase alphabetical input should be accepted and map to same offset as uppercase
109 {
111 "a",
112 true,
113 0,
114 },
115 {
117 "xy",
118 true,
119 648,
120 },
121 {
123 "a",
124 true,
125 0,
126 },
127 // Hex lowercase should NOT be accepted (hex only allows uppercase A-F)
128 {
130 "a0",
131 false,
132 0,
133 },
134 };
135 // clang-format on
136
137 for( const auto& c : cases )
138 {
139 ARRAY_AXIS axis;
140 axis.SetAxisType( c.m_axis_type );
141
142 bool offset_ok = axis.SetOffset( c.m_offset_str );
143
144 BOOST_CHECK_EQUAL( offset_ok, c.m_exp_valid );
145
146 if( c.m_exp_valid )
147 {
148 BOOST_CHECK_EQUAL( axis.GetOffset(), c.m_exp_offset );
149 }
150 }
151}
152
162
164{
165 std::string m_case_name;
167 int m_num;
168 std::vector<std::string> m_exp_names;
169};
170
171
172// clang-format off
173static const std::vector<ARRAY_AXIS_NAMING_CASE> axis_name_cases = {
174 {
175 "Numeric",
176 {
178 "1",
179 1,
180 },
181 6,
182 { "1", "2", "3", "4", "5", "6" },
183 },
184 {
185 // Test alphabetical
186 "Alpha",
187 {
189 "A",
190 1,
191 },
192 3,
193 { "A", "B", "C" },
194 },
195 {
196 // Test alphabetical with 2nd col
197 "Alpha 2nd col",
198 {
200 "Y",
201 1,
202 },
203 4,
204 { "Y", "Z", "AA", "AB" },
205 },
206 {
207 "Numeric skip",
208 {
210 "11",
211 2,
212 },
213 6,
214 { "11", "13", "15", "17", "19", "21" },
215 },
216 {
217 // Test lowercase alphabetical input produces lowercase output
218 "Alpha lowercase",
219 {
221 "a",
222 1,
223 },
224 3,
225 { "a", "b", "c" },
226 },
227 {
228 // Test lowercase alphabetical with 2nd col
229 "Alpha lowercase 2nd col",
230 {
232 "y",
233 1,
234 },
235 4,
236 { "y", "z", "aa", "ab" },
237 },
238 {
239 // Test lowercase no-IOSQXZ alphabet
240 "Alpha no IOSQXZ lowercase",
241 {
243 "a",
244 1,
245 },
246 5,
247 { "a", "b", "c", "d", "e" },
248 },
249};
250// clang-format on
251
256{
257 for( const auto& c : axis_name_cases )
258 {
259 BOOST_TEST_CONTEXT( c.m_case_name )
260 {
261 ARRAY_AXIS axis;
262 axis.SetAxisType( c.m_prms.m_axis_type );
263 axis.SetStep( c.m_prms.m_step );
264
265 bool start_ok = axis.SetOffset( c.m_prms.m_start_at );
266
267 // All these examples have valid start offsets
268 BOOST_CHECK( start_ok );
269
270 std::vector<std::string> names;
271
272 for( int i = 0; i < c.m_num; i++ )
273 {
274 names.push_back( axis.GetItemNumber( i ).ToStdString() );
275 }
276
277 BOOST_CHECK_EQUAL_COLLECTIONS(
278 names.begin(), names.end(), c.m_exp_names.begin(), c.m_exp_names.end() );
279 }
280 }
281}
282
Class that contains information about a single array axis and the numbering of items along that axis.
Definition array_axis.h:40
bool SetOffset(const wxString &aOffsetName)
Set the axis start (as a string, which should decode to a valid index in the alphabet),...
wxString GetItemNumber(int n) const
Get the position number (name) for the n'th axis point.
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
@ NUMBERING_NUMERIC
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
Definition array_axis.h:44
@ NUMBERING_ALPHA_NO_IOSQXZ
Alphabet, excluding IOSQXZ.
Definition array_axis.h:53
@ NUMBERING_ALPHA_FULL
Full 26-character alphabet.
Definition array_axis.h:54
void SetStep(int aStep)
Set the skip between consecutive numbers (useful when doing a partial array, e.g.
int GetOffset() const
Get the numbering offset for the axis.
std::vector< std::string > m_exp_names
ARRAY_AXIS_NAMING_PARAMS m_prms
Data for testing a single array axis.
ARRAY_AXIS::NUMBERING_TYPE m_axis_type
Declare the test suite.
ARRAY_AXIS::NUMBERING_TYPE m_axis_type
static const std::vector< ARRAY_AXIS_NAMING_CASE > axis_name_cases
BOOST_AUTO_TEST_CASE(ValidOffsets)
Check we can get valid (or invalid) offsets as expected.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")