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 (C) 2019 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
30
31#include <array_axis.h>
32
36BOOST_AUTO_TEST_SUITE( ArrayAxis )
37
39{
41 std::string m_offset_str;
44};
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 };
109 // clang-format on
110
111 for( const auto& c : cases )
112 {
113 ARRAY_AXIS axis;
114 axis.SetAxisType( c.m_axis_type );
115
116 bool offset_ok = axis.SetOffset( c.m_offset_str );
117
118 BOOST_CHECK_EQUAL( offset_ok, c.m_exp_valid );
119
120 if( c.m_exp_valid )
121 {
122 BOOST_CHECK_EQUAL( axis.GetOffset(), c.m_exp_offset );
123 }
124 }
125}
126
131{
133 std::string m_start_at;
135};
136
138{
139 std::string m_case_name;
141 int m_num;
142 std::vector<std::string> m_exp_names;
143};
144
145
146// clang-format off
147static const std::vector<ARRAY_AXIS_NAMING_CASE> axis_name_cases = {
148 {
149 "Numeric",
150 {
152 "1",
153 1,
154 },
155 6,
156 { "1", "2", "3", "4", "5", "6" },
157 },
158 {
159 // Test alphabetical
160 "Alpha",
161 {
163 "A",
164 1,
165 },
166 3,
167 { "A", "B", "C" },
168 },
169 {
170 // Test alphabetical with 2nd col
171 "Alpha 2nd col",
172 {
174 "Y",
175 1,
176 },
177 4,
178 { "Y", "Z", "AA", "AB" },
179 },
180 {
181 "Numeric skip",
182 {
184 "11",
185 2,
186 },
187 6,
188 { "11", "13", "15", "17", "19", "21" },
189 },
190};
191// clang-format on
192
197{
198 for( const auto& c : axis_name_cases )
199 {
200 BOOST_TEST_CONTEXT( c.m_case_name )
201 {
202 ARRAY_AXIS axis;
203 axis.SetAxisType( c.m_prms.m_axis_type );
204 axis.SetStep( c.m_prms.m_step );
205
206 bool start_ok = axis.SetOffset( c.m_prms.m_start_at );
207
208 // All these examples have valid start offsets
209 BOOST_CHECK( start_ok );
210
211 std::vector<std::string> names;
212
213 for( int i = 0; i < c.m_num; i++ )
214 {
215 names.push_back( axis.GetItemNumber( i ).ToStdString() );
216 }
217
218 BOOST_CHECK_EQUAL_COLLECTIONS(
219 names.begin(), names.end(), c.m_exp_names.begin(), c.m_exp_names.end() );
220 }
221 }
222}
223
224BOOST_AUTO_TEST_SUITE_END()
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)
Definition: array_axis.cpp:102
wxString GetItemNumber(int n) const
Get the position number (name) for the n'th axis point.
Definition: array_axis.cpp:133
void SetAxisType(NUMBERING_TYPE aType)
Set the axis numbering type.
Definition: array_axis.cpp:96
@ NUMBERING_NUMERIC
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
Definition: array_axis.h:44
@ NUMBERING_HEX
Definition: array_axis.h:45
@ NUMBERING_ALPHA_FULL
Full 26-character alphabet.
Definition: array_axis.h:52
void SetStep(int aStep)
Set the skip between consecutive numbers (useful when doing a partial array, e.g.
Definition: array_axis.cpp:127
int GetOffset() const
Get the numbering offset for the axis.
Definition: array_axis.cpp:121
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
std::string m_offset_str
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_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
#define BOOST_TEST_CONTEXT(A)