KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_increment.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
25
26#include <increment.h>
27
28
32BOOST_AUTO_TEST_SUITE( StringIncrement )
33
34
36{
37 wxString input;
38 int delta;
39 size_t part;
40 wxString expected;
41};
42
43
48{
49 const std::vector<INCREMENT_TEST_CASE> cases{
50 // Null
51 { "", 1, 0, "nullopt" },
52 { "", 1, 1, "nullopt" },
53 { "", -1, 1, "nullopt" },
54 // Up
55 { "1", 1, 0, "2" },
56 { "1", 9, 0, "10" },
57 // Down
58 { "2", -1, 0, "1" },
59 { "10", -1, 0, "9" },
60 // Down from 0
61 { "0", -1, 0, "nullopt" },
62 // Ran out of a parts
63 { "1", 1, 1, "nullopt" },
64 // Leading zeros preserved
65 { "01", 1, 0, "02" },
66 // Alpha
67 { "A", 1, 0, "B" },
68 { "E", -1, 0, "D" },
69 // Skip I
70 { "H", 1, 0, "J" },
71 { "J", -1, 0, "H" },
72 // But I works if it's there
73 { "I", 1, 0, "J" },
74 { "I", -1, 0, "H" },
75 // Alpha wrap
76 { "Z", 1, 0, "AA" },
77 // Reject huge alphabetic value
78 { "ABB", 1, 0, "nullopt" },
79 // Dashes skipped
80 { "A-1", 1, 0, "A-2" },
81 { "A-1", 1, 1, "B-1" },
82 // Mixed alphabetic+numeric string behavior
83 { "A12", 1, 0, "A13" },
84 { "A12", -1, 0, "A11" },
85 { "A12", 1, 1, "B12" },
86 { "A12", -1, 1, "nullopt" },
87 };
88
89 STRING_INCREMENTER incrementer;
90 incrementer.SetSkipIOSQXZ( true );
91
92 for( const auto& c : cases )
93 {
94 BOOST_TEST_INFO( "Input: " << c.input << " Delta: " << c.delta << " Part: " << c.part );
95 wxString result = incrementer.Increment( c.input, c.delta, c.part ).value_or( "nullopt" );
96 BOOST_CHECK_EQUAL( result, c.expected );
97 }
98}
99
100
102{
103 wxString input;
104 const wxString& alphabet;
106};
107
108
109BOOST_AUTO_TEST_CASE( AlphabeticIndexes )
110{
111 const wxString alphabet = "ABCDEFGHJKLMNPRTUVWY";
112
113 const std::vector<ALPHABETIC_TEST_CASE> cases{ {
114 { "A", alphabet, 0 },
115 { "B", alphabet, 1 },
116 { "Y", alphabet, 19 },
117 { "AA", alphabet, 20 },
118 { "AY", alphabet, 39 },
119 } };
120
121 for( const auto& c : cases )
122 {
123 BOOST_TEST_INFO( "Input: " << c.input << " <-> " << c.expected );
124
125 const int fromString = IndexFromAlphabetic( c.input, c.alphabet );
126 BOOST_CHECK_EQUAL( fromString, c.expected );
127
128 const wxString fromIndex = AlphabeticFromIndex( c.expected, c.alphabet, true );
129 BOOST_CHECK_EQUAL( fromIndex, c.input );
130 }
131}
132
133
Heuristically increment a string's n'th part from the right.
Definition increment.h:48
void SetSkipIOSQXZ(bool aSkip)
If a alphabetic part is found, skip the letters I, O, S, Q, X, Z.
Definition increment.h:54
std::optional< wxString > Increment(const wxString &aStr, int aDelta, size_t aRightIndex) const
Increment the n-th part from the right of the given string.
Definition increment.cpp:86
KICOMMON_API int IndexFromAlphabetic(const wxString &aStr, const wxString &aAlphabet)
Attempt to convert a string to an integer, assuming it is an alphabetic string like "A",...
wxString KICOMMON_API AlphabeticFromIndex(size_t aN, const wxString &aAlphabet, bool aZeroBasedNonUnitCols)
Get an alphabetic string like A, B, ... Z, AA, AB, ... ZZ, AAA, ...
const wxString & alphabet
Declares a struct as the Boost test fixture.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(BasicCase)
Check formatting the point.
BOOST_TEST_INFO("Parsed: "<< path)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")