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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
27#include <array_axis.h>
28
32BOOST_AUTO_TEST_SUITE( ArrayAxis )
33
41
42
46BOOST_AUTO_TEST_CASE( ValidOffsets )
47{
48 // clang-format off
49 const std::vector<VALID_OFFSET_CASE> cases = {
50 {
52 "0",
53 true,
54 0,
55 },
56 {
58 "1",
59 true,
60 1,
61 },
62 {
64 "1234",
65 true,
66 1234,
67 },
68 {
70 "",
71 false,
72 0,
73 },
74 {
76 "www",
77 false,
78 0,
79 },
80 {
82 "A",
83 true,
84 0,
85 },
86 {
88 "XY",
89 true,
90 648,
91 },
92 {
94 "A0",
95 true,
96 160,
97 },
98 {
100 "G0",
101 false,
102 0,
103 },
104 // Lowercase alphabetical input should be accepted and map to same offset as uppercase
105 {
107 "a",
108 true,
109 0,
110 },
111 {
113 "xy",
114 true,
115 648,
116 },
117 {
119 "a",
120 true,
121 0,
122 },
123 // Hex lowercase should NOT be accepted (hex only allows uppercase A-F)
124 {
126 "a0",
127 false,
128 0,
129 },
130 };
131 // clang-format on
132
133 for( const auto& c : cases )
134 {
135 ARRAY_AXIS axis;
136 axis.SetAxisType( c.m_axis_type );
137
138 bool offset_ok = axis.SetOffset( c.m_offset_str );
139
140 BOOST_CHECK_EQUAL( offset_ok, c.m_exp_valid );
141
142 if( c.m_exp_valid )
143 {
144 BOOST_CHECK_EQUAL( axis.GetOffset(), c.m_exp_offset );
145 }
146 }
147}
148
158
160{
161 std::string m_case_name;
163 int m_num;
164 std::vector<std::string> m_exp_names;
165};
166
167
168// clang-format off
169static const std::vector<ARRAY_AXIS_NAMING_CASE> axis_name_cases = {
170 {
171 "Numeric",
172 {
174 "1",
175 1,
176 },
177 6,
178 { "1", "2", "3", "4", "5", "6" },
179 },
180 {
181 // Test alphabetical
182 "Alpha",
183 {
185 "A",
186 1,
187 },
188 3,
189 { "A", "B", "C" },
190 },
191 {
192 // Test alphabetical with 2nd col
193 "Alpha 2nd col",
194 {
196 "Y",
197 1,
198 },
199 4,
200 { "Y", "Z", "AA", "AB" },
201 },
202 {
203 "Numeric skip",
204 {
206 "11",
207 2,
208 },
209 6,
210 { "11", "13", "15", "17", "19", "21" },
211 },
212 {
213 // Test lowercase alphabetical input produces lowercase output
214 "Alpha lowercase",
215 {
217 "a",
218 1,
219 },
220 3,
221 { "a", "b", "c" },
222 },
223 {
224 // Test lowercase alphabetical with 2nd col
225 "Alpha lowercase 2nd col",
226 {
228 "y",
229 1,
230 },
231 4,
232 { "y", "z", "aa", "ab" },
233 },
234 {
235 // Test lowercase no-IOSQXZ alphabet
236 "Alpha no IOSQXZ lowercase",
237 {
239 "a",
240 1,
241 },
242 5,
243 { "a", "b", "c", "d", "e" },
244 },
245};
246// clang-format on
247
252{
253 for( const auto& c : axis_name_cases )
254 {
255 BOOST_TEST_CONTEXT( c.m_case_name )
256 {
257 ARRAY_AXIS axis;
258 axis.SetAxisType( c.m_prms.m_axis_type );
259 axis.SetStep( c.m_prms.m_step );
260
261 bool start_ok = axis.SetOffset( c.m_prms.m_start_at );
262
263 // All these examples have valid start offsets
264 BOOST_CHECK( start_ok );
265
266 std::vector<std::string> names;
267
268 for( int i = 0; i < c.m_num; i++ )
269 {
270 names.push_back( axis.GetItemNumber( i ).ToStdString() );
271 }
272
273 BOOST_CHECK_EQUAL_COLLECTIONS(
274 names.begin(), names.end(), c.m_exp_names.begin(), c.m_exp_names.end() );
275 }
276 }
277}
278
Class that contains information about a single array axis and the numbering of items along that axis.
Definition array_axis.h:36
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:40
@ NUMBERING_ALPHA_NO_IOSQXZ
Alphabet, excluding IOSQXZ.
Definition array_axis.h:49
@ NUMBERING_ALPHA_FULL
Full 26-character alphabet.
Definition array_axis.h:50
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")